output
stringlengths 52
181k
| instruction
stringlengths 296
182k
|
---|---|
#include<iostream>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
int N, H[100000], ans, mx;
int main() {
cin >> N;
rep(i, N) cin >> H[i];
string ans = "Yes";
rep(i, N) {
if (H[i] < mx - 1) ans = "No";
mx = max(mx, H[i]);
}
cout << ans << endl;
} | ### Prompt
Your challenge is to write a CPP solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<iostream>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
int N, H[100000], ans, mx;
int main() {
cin >> N;
rep(i, N) cin >> H[i];
string ans = "Yes";
rep(i, N) {
if (H[i] < mx - 1) ans = "No";
mx = max(mx, H[i]);
}
cout << ans << endl;
}
``` |
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int h[n];
for(int i=0;i<n;i++){
cin >> h[i];
}
for(int i=n-1;i>0;i--){
if(h[i-1]-h[i]>1){
cout << "No" << endl;
return 0;
}
else if(h[i-1]-h[i]==1){
h[i-1] --;
}
}
cout << "Yes" << endl;
return 0;
} | ### Prompt
Please create a solution in CPP to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int h[n];
for(int i=0;i<n;i++){
cin >> h[i];
}
for(int i=n-1;i>0;i--){
if(h[i-1]-h[i]>1){
cout << "No" << endl;
return 0;
}
else if(h[i-1]-h[i]==1){
h[i-1] --;
}
}
cout << "Yes" << endl;
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,h,m=0;
cin>>n;
for(int i=1;i<=n;i++){
cin>>h;
if(h<m){cout<<"No";return 0;}
m=max(m,h-1);
}
cout<<"Yes";
} | ### Prompt
Your task is to create a Cpp solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,h,m=0;
cin>>n;
for(int i=1;i<=n;i++){
cin>>h;
if(h<m){cout<<"No";return 0;}
m=max(m,h-1);
}
cout<<"Yes";
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);cin.tie(0);
int n;
cin >> n;
int lst = -1;
for(int i=0; i<n; i++) {
int cur;
cin >> cur;
if(cur > lst)
lst = cur-1;
else if(cur < lst)
return !(cout << "No");
}
cout << "Yes";
} | ### Prompt
Your challenge is to write a CPP solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);cin.tie(0);
int n;
cin >> n;
int lst = -1;
for(int i=0; i<n; i++) {
int cur;
cin >> cur;
if(cur > lst)
lst = cur-1;
else if(cur < lst)
return !(cout << "No");
}
cout << "Yes";
}
``` |
#include<cstdio>
int n;
int a[100010];
int main(){
scanf("%d", &n);
for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
for(int i = n; i >= 2; i--){
if(a[i - 1] - 1 > a[i]){
printf("No");
return 0;
}
else if(a[i - 1] - 1 == a[i]) a[i - 1] = a[i - 1] - 1;
}
printf("Yes");
return 0;
} | ### Prompt
Please formulate a Cpp solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<cstdio>
int n;
int a[100010];
int main(){
scanf("%d", &n);
for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
for(int i = n; i >= 2; i--){
if(a[i - 1] - 1 > a[i]){
printf("No");
return 0;
}
else if(a[i - 1] - 1 == a[i]) a[i - 1] = a[i - 1] - 1;
}
printf("Yes");
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,a;
cin>>n;
int ans=0;
for(int i=0;i<n;i++)
{
cin>>a;
if(a-ans<=-2)
{
cout<<"No";
return 0;
}
ans=max(a,ans);
}
cout<<"Yes";
return 0;
} | ### Prompt
Construct a CPP code solution to the problem outlined:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,a;
cin>>n;
int ans=0;
for(int i=0;i<n;i++)
{
cin>>a;
if(a-ans<=-2)
{
cout<<"No";
return 0;
}
ans=max(a,ans);
}
cout<<"Yes";
return 0;
}
``` |
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
long N,h[100000];
cin>>N;
for(int i=0;i<N;i++)cin>>h[i];
for(int i=N-1;i>0;i--){
if(h[i-1]-1>h[i]){cout<<"No";return 0;}
else if(h[i-1]-1==h[i])h[i-1]--;
}
cout<<"Yes";
return 0;
} | ### Prompt
Please provide a cpp coded solution to the problem described below:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
long N,h[100000];
cin>>N;
for(int i=0;i<N;i++)cin>>h[i];
for(int i=N-1;i>0;i--){
if(h[i-1]-1>h[i]){cout<<"No";return 0;}
else if(h[i-1]-1==h[i])h[i-1]--;
}
cout<<"Yes";
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int main (){
int n;cin>>n;
int a[100001];
for(int i=0;i<n;i++)scanf("%d",&a[i]);
int ma=a[0];
for(int i=1;i<n;i++){
ma=max(ma,a[i]);
if(ma-a[i]>=2){
puts("No");
return 0;
}
}
puts("Yes");
return 0;
}
| ### Prompt
Create a solution in Cpp for the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int main (){
int n;cin>>n;
int a[100001];
for(int i=0;i<n;i++)scanf("%d",&a[i]);
int ma=a[0];
for(int i=1;i<n;i++){
ma=max(ma,a[i]);
if(ma-a[i]>=2){
puts("No");
return 0;
}
}
puts("Yes");
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n, la;
int main() {
scanf("%d", &n);
while (n--) {
int tmp;
scanf("%d", &tmp);
if (tmp < la) {
puts("No");
return 0;
}
if (tmp - 1 >= la)
tmp--;
la = tmp;
}
puts("Yes");
}
| ### Prompt
Create a solution in Cpp for the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, la;
int main() {
scanf("%d", &n);
while (n--) {
int tmp;
scanf("%d", &tmp);
if (tmp < la) {
puts("No");
return 0;
}
if (tmp - 1 >= la)
tmp--;
la = tmp;
}
puts("Yes");
}
``` |
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int M=1e5+5;
int main(){
ll n,a[M],f=1,maxn;
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
if(i==0) maxn=a[i];
if(a[i]>maxn) maxn=a[i];
else if(maxn-a[i]>1) f=0;
}
if(f) cout<<"Yes";
else cout<<"No";
return 0;
} | ### Prompt
Develop a solution in cpp to the problem described below:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int M=1e5+5;
int main(){
ll n,a[M],f=1,maxn;
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
if(i==0) maxn=a[i];
if(a[i]>maxn) maxn=a[i];
else if(maxn-a[i]>1) f=0;
}
if(f) cout<<"Yes";
else cout<<"No";
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int n, h[(int)1e5];
int main(){
cin >> n;
for(int i = 0; i < n; ++i) cin >> h[i];
for(int i = n - 1; i >= 0; --i){
if(h[i-1] > h[i]){
h[i-1]--;
if(h[i-1] > h[i]){
cout << "No" << endl;
return 0;
}
}
}
cout << "Yes" << endl;
} | ### Prompt
Generate a CPP solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int n, h[(int)1e5];
int main(){
cin >> n;
for(int i = 0; i < n; ++i) cin >> h[i];
for(int i = n - 1; i >= 0; --i){
if(h[i-1] > h[i]){
h[i-1]--;
if(h[i-1] > h[i]){
cout << "No" << endl;
return 0;
}
}
}
cout << "Yes" << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string ans="Yes";
int N;
cin >> N;
int H1=0,H2;
for(int i=0; i<N; i++){
cin >> H2;
if(H1>H2)ans="No";
if(H1!=H2)H1=H2-1;
}
cout << ans << endl;
} | ### Prompt
Please create a solution in cpp to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string ans="Yes";
int N;
cin >> N;
int H1=0,H2;
for(int i=0; i<N; i++){
cin >> H2;
if(H1>H2)ans="No";
if(H1!=H2)H1=H2-1;
}
cout << ans << endl;
}
``` |
#include<bits/stdc++.h>
using namespace std;
#define maxn 100005
int a[maxn];
int main(){
int n;scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",a+i);
if(a[i]>a[i-1])a[i]--;
else if(a[i]<a[i-1]){
puts("No");return 0;
}
}
puts("Yes");
return 0;
} | ### Prompt
Create a solution in cpp for the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
#define maxn 100005
int a[maxn];
int main(){
int n;scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",a+i);
if(a[i]>a[i-1])a[i]--;
else if(a[i]<a[i-1]){
puts("No");return 0;
}
}
puts("Yes");
return 0;
}
``` |
/*
17/10/2017
*/
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
int n;
cin>>n;
int a[n];
bool ok=1;
int mx=0;
for(int i=0;i<n;i++)
{
cin>>a[i];
if(mx-a[i]>=2)
{
ok=0;
}
mx=max(mx,a[i]);
}
cout<<(ok ? "Yes" : "No")<<endl;
} | ### Prompt
Create a solution in cpp for the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
/*
17/10/2017
*/
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
int n;
cin>>n;
int a[n];
bool ok=1;
int mx=0;
for(int i=0;i<n;i++)
{
cin>>a[i];
if(mx-a[i]>=2)
{
ok=0;
}
mx=max(mx,a[i]);
}
cout<<(ok ? "Yes" : "No")<<endl;
}
``` |
#include<iostream>
using namespace std;
int n;
int main(){
cin>>n;
int h[n];
for(int i=0;i<n;i++)cin>>h[i];
for(int i=n-1;i>=0;i--){
if(h[i-1]>h[i])h[i-1]--;
if(h[i-1]>h[i]){cout<<"No"<<endl;return 0;}
}
cout<<"Yes"<<endl;
return 0;
} | ### Prompt
Construct a cpp code solution to the problem outlined:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<iostream>
using namespace std;
int n;
int main(){
cin>>n;
int h[n];
for(int i=0;i<n;i++)cin>>h[i];
for(int i=n-1;i>=0;i--){
if(h[i-1]>h[i])h[i-1]--;
if(h[i-1]>h[i]){cout<<"No"<<endl;return 0;}
}
cout<<"Yes"<<endl;
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int H[N];
int main()
{
#ifdef kcz
freopen("1.in","r",stdin);
#endif
int n;
cin>>n;
for(int i=1;i<=n;++i)scanf("%d",H+i);
for(int i=n;--i;)
if(H[i]>H[i+1])
if(--H[i]>H[i+1])
{
puts("No");
exit(0);
}
puts("Yes");
} | ### Prompt
Please formulate a CPP solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int H[N];
int main()
{
#ifdef kcz
freopen("1.in","r",stdin);
#endif
int n;
cin>>n;
for(int i=1;i<=n;++i)scanf("%d",H+i);
for(int i=n;--i;)
if(H[i]>H[i+1])
if(--H[i]>H[i+1])
{
puts("No");
exit(0);
}
puts("Yes");
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n,a[100005],ma;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i){
scanf("%d",&a[i]);
ma=max(a[i],ma);
if(ma-a[i]>1){
puts("No");
return 0;
}
}
puts("Yes");
} | ### Prompt
Please provide a CPP coded solution to the problem described below:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n,a[100005],ma;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i){
scanf("%d",&a[i]);
ma=max(a[i],ma);
if(ma-a[i]>1){
puts("No");
return 0;
}
}
puts("Yes");
}
``` |
#include "bits/stdc++.h"
using namespace std;
const int N=1e5+20;
int n,a[N];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=n;i>1;i--)
{
if(a[i]>=a[i-1]) continue;
a[i-1]--;
if(a[i]<a[i-1]) return 0 * printf("No");
}
printf("Yes");
} | ### Prompt
Create a solution in Cpp for the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include "bits/stdc++.h"
using namespace std;
const int N=1e5+20;
int n,a[N];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=n;i>1;i--)
{
if(a[i]>=a[i-1]) continue;
a[i-1]--;
if(a[i]<a[i-1]) return 0 * printf("No");
}
printf("Yes");
}
``` |
#include<bits/stdc++.h>
using namespace std;
int n,h[100005],m;
int main()
{
cin>>n;
for(int i=1;i<=n;i++){
cin>>h[i];
if(h[i]<m)cout<<"No",exit(0);
m=max(m,h[i]-1);
}
cout<<"Yes";
return 0;
} | ### Prompt
Your challenge is to write a Cpp solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int n,h[100005],m;
int main()
{
cin>>n;
for(int i=1;i<=n;i++){
cin>>h[i];
if(h[i]<m)cout<<"No",exit(0);
m=max(m,h[i]-1);
}
cout<<"Yes";
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
#define N 100005
int main()
{
int n;
cin>>n;
int d[N];
for(int i=0;i<n;i++)
cin>>d[i];
d[0]--;
for(int i=1;i<n;i++)
if(d[i]<d[i-1])
{
cout<<"No\n";
return 0;
}
else d[i]=max(d[i-1],d[i]-1);
cout<<"Yes\n";
return 0;
} | ### Prompt
Your task is to create a cpp solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
#define N 100005
int main()
{
int n;
cin>>n;
int d[N];
for(int i=0;i<n;i++)
cin>>d[i];
d[0]--;
for(int i=1;i<n;i++)
if(d[i]<d[i-1])
{
cout<<"No\n";
return 0;
}
else d[i]=max(d[i-1],d[i]-1);
cout<<"Yes\n";
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin>>n;
int mx = 0;
for(int i = 1; i<=n; i++){
int a; cin>>a;
if((mx - a) > 1){
cout<<"No\n";
return 0;
}
mx = max(mx, a);
}
cout<<"Yes\n";
return 0;
} | ### Prompt
Develop a solution in CPP to the problem described below:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin>>n;
int mx = 0;
for(int i = 1; i<=n; i++){
int a; cin>>a;
if((mx - a) > 1){
cout<<"No\n";
return 0;
}
mx = max(mx, a);
}
cout<<"Yes\n";
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int a[n];
for (int i=1;i<=n;i++)
{
cin>>a[i];
}
for (int i=n-1;i>=1;i--)
{
if (a[i]>a[i+1]+1)
{
cout<<"No"<<endl;
return 0;
}
if (a[i]==a[i+1]+1)
{
a[i]--;
}
}
cout<<"Yes"<<endl;
return 0;
} | ### Prompt
Please create a solution in Cpp to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int a[n];
for (int i=1;i<=n;i++)
{
cin>>a[i];
}
for (int i=n-1;i>=1;i--)
{
if (a[i]>a[i+1]+1)
{
cout<<"No"<<endl;
return 0;
}
if (a[i]==a[i+1]+1)
{
a[i]--;
}
}
cout<<"Yes"<<endl;
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;int a[1000000];int lea=0;
int main(){
int n;
cin>>n;
if(n==1){puts("Yes");exit(0);
}
else{
for(int i=1;i<=n;i++){scanf("%d",&a[i]);
if(lea>a[i]) {cout<<"No";exit(0);}
if(lea<a[i]) lea=max(a[i]-1,lea);
}puts("Yes");
}
} | ### Prompt
Construct a CPP code solution to the problem outlined:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;int a[1000000];int lea=0;
int main(){
int n;
cin>>n;
if(n==1){puts("Yes");exit(0);
}
else{
for(int i=1;i<=n;i++){scanf("%d",&a[i]);
if(lea>a[i]) {cout<<"No";exit(0);}
if(lea<a[i]) lea=max(a[i]-1,lea);
}puts("Yes");
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin>>n;
int a[n];
for(int i=0;i<n;i++) cin>>a[i];
int i;
for(i=n-1;i>0;i--) {
if(a[i]>=a[i-1]) continue;
if(a[i-1]==a[i]+1) a[i-1]--;
else {
cout<<"No"<<endl; break;
}
}
if(i==0) cout<<"Yes"<<endl;
return 0;
} | ### Prompt
Develop a solution in cpp to the problem described below:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin>>n;
int a[n];
for(int i=0;i<n;i++) cin>>a[i];
int i;
for(i=n-1;i>0;i--) {
if(a[i]>=a[i-1]) continue;
if(a[i-1]==a[i]+1) a[i-1]--;
else {
cout<<"No"<<endl; break;
}
}
if(i==0) cout<<"Yes"<<endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
vector<int> v(n);
for (int& i:v) cin >> i;
vector<int> v2=v;
sort(v2.begin(),v2.end());
bool ok=true;
for (int i=0; i<n; ++i){
if (abs(v[i]-v2[i]) > 1) ok = false;
}
if (ok) cout << "Yes";
else cout << "No";
}
| ### Prompt
Please formulate a cpp solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
vector<int> v(n);
for (int& i:v) cin >> i;
vector<int> v2=v;
sort(v2.begin(),v2.end());
bool ok=true;
for (int i=0; i<n; ++i){
if (abs(v[i]-v2[i]) > 1) ok = false;
}
if (ok) cout << "Yes";
else cout << "No";
}
``` |
#include <iostream>
using namespace std;
typedef long long ll;
int main(){
ll n;cin>>n;ll a=0,b=0,c=1;
for(ll i=0;i<n;i++){
cin>> a;
b=max(a,b);
if((b-a)>=2){c=0;break;}
}
if(c==0){
cout<<"No"<<endl;
}else{
cout << "Yes"<<endl;
}
} | ### Prompt
Generate a cpp solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <iostream>
using namespace std;
typedef long long ll;
int main(){
ll n;cin>>n;ll a=0,b=0,c=1;
for(ll i=0;i<n;i++){
cin>> a;
b=max(a,b);
if((b-a)>=2){c=0;break;}
}
if(c==0){
cout<<"No"<<endl;
}else{
cout << "Yes"<<endl;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
vector<int> h(n);
int mxh = 0;
string ans = "Yes";
for(int i=0; i<n; i++){
cin >> h[i];
if(h[i]>mxh){
mxh = h[i];
}
else if(h[i]<mxh-1){
ans = "No";
}
}
cout << ans << endl;
} | ### Prompt
Your challenge is to write a cpp solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
vector<int> h(n);
int mxh = 0;
string ans = "Yes";
for(int i=0; i<n; i++){
cin >> h[i];
if(h[i]>mxh){
mxh = h[i];
}
else if(h[i]<mxh-1){
ans = "No";
}
}
cout << ans << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n,a[123456],c;
int main(){
cin>>n>>a[0];
int m=a[0];
for(int i=1;i<n;i++){
cin>>a[i];
a[i]-=m;
if(a[i]<0)a[i]+=1;
m+=a[i];
}
for(int i=0;i<n;i++){
if(a[i]<0){//why?
if(c==0)cout<<"No"<<endl;
c++;
}
}
if(c==0)cout<<"Yes"<<endl;
}
| ### Prompt
Please formulate a CPP solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n,a[123456],c;
int main(){
cin>>n>>a[0];
int m=a[0];
for(int i=1;i<n;i++){
cin>>a[i];
a[i]-=m;
if(a[i]<0)a[i]+=1;
m+=a[i];
}
for(int i=0;i<n;i++){
if(a[i]<0){//why?
if(c==0)cout<<"No"<<endl;
c++;
}
}
if(c==0)cout<<"Yes"<<endl;
}
``` |
#include<iostream>
using namespace std;
int main(){
int n, a, b;
bool p = true;
cin >> n;
cin >> a;
for(int i = 1; i < n; i++){
cin >> b;
if(a > b) p = false;
if(a < b) b--;
a = b;
}
if(p) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
} | ### Prompt
Your challenge is to write a CPP solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<iostream>
using namespace std;
int main(){
int n, a, b;
bool p = true;
cin >> n;
cin >> a;
for(int i = 1; i < n; i++){
cin >> b;
if(a > b) p = false;
if(a < b) b--;
a = b;
}
if(p) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
long long a[100000+10];
int main()
{
long long n,i;
cin>>n;
for(i=0;i<n;i++)
{
cin>>a[i];
}
long long maxl=a[0];
for(i=1;i<n;i++)
{
maxl=max(a[i],maxl);
if(maxl-a[i]>1)
{
cout<<"No";
return 0;
}
}
cout<<"Yes";
} | ### Prompt
Generate a Cpp solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
long long a[100000+10];
int main()
{
long long n,i;
cin>>n;
for(i=0;i<n;i++)
{
cin>>a[i];
}
long long maxl=a[0];
for(i=1;i<n;i++)
{
maxl=max(a[i],maxl);
if(maxl-a[i]>1)
{
cout<<"No";
return 0;
}
}
cout<<"Yes";
}
``` |
#include <iostream>
using namespace std;
int main(){
int n;cin>>n;
int a[n];
for(int i = 0; n > i; i++)cin>>a[i];
int mx = 0;
for(int i = 0; n > i; i++){
if(mx > a[i]){
cout << "No" << endl;
return 0;
}
mx = max(mx,a[i]-1);
}
cout << "Yes" << endl;
} | ### Prompt
Generate a Cpp solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <iostream>
using namespace std;
int main(){
int n;cin>>n;
int a[n];
for(int i = 0; n > i; i++)cin>>a[i];
int mx = 0;
for(int i = 0; n > i; i++){
if(mx > a[i]){
cout << "No" << endl;
return 0;
}
mx = max(mx,a[i]-1);
}
cout << "Yes" << endl;
}
``` |
#include<iostream>
using namespace std;
int main(){
int n,k=0,flag=0;
int a[100005];
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
if(a[i]>k){
k=a[i];
}
if(k-a[i]>=2){
flag=1;
break;
}
}
if(flag){
cout<<"No";
}
else{
cout<<"Yes";
}
} | ### Prompt
Create a solution in Cpp for the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<iostream>
using namespace std;
int main(){
int n,k=0,flag=0;
int a[100005];
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
if(a[i]>k){
k=a[i];
}
if(k-a[i]>=2){
flag=1;
break;
}
}
if(flag){
cout<<"No";
}
else{
cout<<"Yes";
}
}
``` |
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int main(){
int N;
cin >>N;
int MAX=0;
for (int i=0;i<N;i++){
int H;
cin >>H;
if (MAX>=H+2){
cout <<"No";
exit(0);
}
MAX=max(MAX,H);
}
cout <<"Yes";
} | ### Prompt
Generate a cpp solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int main(){
int N;
cin >>N;
int MAX=0;
for (int i=0;i<N;i++){
int H;
cin >>H;
if (MAX>=H+2){
cout <<"No";
exit(0);
}
MAX=max(MAX,H);
}
cout <<"Yes";
}
``` |
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int h, max = -1;
for (int i = 0; i < n; i++) {
cin >> h;
if (h > max) max = h;
if (h < max - 1) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
} | ### Prompt
Your task is to create a CPP solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int h, max = -1;
for (int i = 0; i < n; i++) {
cin >> h;
if (h > max) max = h;
if (h < max - 1) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int n,i,a[100009],f;
int main(){
scanf("%d",&n);
for(i=0;i<n;i++) scanf("%d",&a[i]);
for(i=n-1;i>=1;i--){
if(a[i]<a[i-1]) a[i-1]--;
if(a[i]<a[i-1]){
f=1; break;
}
}
if(f==1) printf("No");
else printf("Yes");
} | ### Prompt
Please formulate a cpp solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int n,i,a[100009],f;
int main(){
scanf("%d",&n);
for(i=0;i<n;i++) scanf("%d",&a[i]);
for(i=n-1;i>=1;i--){
if(a[i]<a[i-1]) a[i-1]--;
if(a[i]<a[i-1]){
f=1; break;
}
}
if(f==1) printf("No");
else printf("Yes");
}
``` |
#include<iostream>
using namespace std;
int a[100005];
int main()
{
int n,maxh=0;
cin >> n;
for(int i=1;i<=n;i++)
cin >> a[i];
maxh=a[1];
for(int i=2;i<=n;i++)
{
if(a[i]-maxh<=-2)
{
cout << "No";
return 0;
}
maxh=max(a[i],maxh);
}
cout << "Yes";
return 0;
} | ### Prompt
Develop a solution in Cpp to the problem described below:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<iostream>
using namespace std;
int a[100005];
int main()
{
int n,maxh=0;
cin >> n;
for(int i=1;i<=n;i++)
cin >> a[i];
maxh=a[1];
for(int i=2;i<=n;i++)
{
if(a[i]-maxh<=-2)
{
cout << "No";
return 0;
}
maxh=max(a[i],maxh);
}
cout << "Yes";
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
int H[N];
for(int i=0;i<N;i++){
cin >> H[i];
}
H[0]--;
bool f=true;
for(int i=1;i<N;i++){
if(H[i-1]<H[i]){ H[i]--; }
else if(H[i-1]>H[i]){ f=false;break; }
}
if(f){ cout << "Yes"; }else{ cout << "No"; }
}
| ### Prompt
Please provide a Cpp coded solution to the problem described below:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
int H[N];
for(int i=0;i<N;i++){
cin >> H[i];
}
H[0]--;
bool f=true;
for(int i=1;i<N;i++){
if(H[i-1]<H[i]){ H[i]--; }
else if(H[i-1]>H[i]){ f=false;break; }
}
if(f){ cout << "Yes"; }else{ cout << "No"; }
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
cin >> a;
vector<int> z(a+1);
string c ="Yes";
for(int i = 1;i < a+1;i++){
cin >> z.at(i);
if(z.at(i-1)<z.at(i))z.at(i)--;
if(z.at(i-1)>z.at(i)){c="No";break;}
}
cout << c << endl;
} | ### Prompt
Create a solution in Cpp for the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
cin >> a;
vector<int> z(a+1);
string c ="Yes";
for(int i = 1;i < a+1;i++){
cin >> z.at(i);
if(z.at(i-1)<z.at(i))z.at(i)--;
if(z.at(i-1)>z.at(i)){c="No";break;}
}
cout << c << endl;
}
``` |
#include <bits/stdc++.h>
int main() {
using namespace std;
unsigned long N;
cin >> N;
for(unsigned long i = 0, j = 1, p = 0; i < N; ++i){
cin >> j;
if(p < j)--j;
if(p > j)return 0 & puts("No");
p = j;
}
puts("Yes");
return 0;
} | ### Prompt
Please formulate a Cpp solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
int main() {
using namespace std;
unsigned long N;
cin >> N;
for(unsigned long i = 0, j = 1, p = 0; i < N; ++i){
cin >> j;
if(p < j)--j;
if(p > j)return 0 & puts("No");
p = j;
}
puts("Yes");
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
long long h[100010],a[100010],maxx=-1;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>h[i];
a[i]=h[i];
if(maxx-h[i]>=2)
{
cout<<"No";
exit(0);
}
maxx=max(maxx,a[i]);
}
cout<<"Yes";
return 0;
} | ### Prompt
Please formulate a Cpp solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
long long h[100010],a[100010],maxx=-1;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>h[i];
a[i]=h[i];
if(maxx-h[i]>=2)
{
cout<<"No";
exit(0);
}
maxx=max(maxx,a[i]);
}
cout<<"Yes";
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int n,h[100009];
int main() {
cin>>n;
for(int i=0;i<n;i++) cin>>h[i];
for(int i=n-2;i>=0;i--) {
if(h[i]-1>h[i+1]) {
cout<<"No"<<endl;
return 0;
}
if(h[i]>h[i+1]) h[i]--;
}
cout<<"Yes"<<endl;
return 0;
} | ### Prompt
Your challenge is to write a cpp solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int n,h[100009];
int main() {
cin>>n;
for(int i=0;i<n;i++) cin>>h[i];
for(int i=n-2;i>=0;i--) {
if(h[i]-1>h[i+1]) {
cout<<"No"<<endl;
return 0;
}
if(h[i]>h[i+1]) h[i]--;
}
cout<<"Yes"<<endl;
return 0;
}
``` |
#include <iostream>
using namespace std;
int n;
int mx=-1;
int main()
{
ios::sync_with_stdio(false);
cin>>n;
for (int i=1;i<=n;i++){
int x;
cin>>x;
if (mx-x>=2){
cout<<"No"<<endl;
return 0;
}
mx=max(mx,x);
}
cout<<"Yes"<<endl;
return 0;
} | ### Prompt
Please formulate a CPP solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <iostream>
using namespace std;
int n;
int mx=-1;
int main()
{
ios::sync_with_stdio(false);
cin>>n;
for (int i=1;i<=n;i++){
int x;
cin>>x;
if (mx-x>=2){
cout<<"No"<<endl;
return 0;
}
mx=max(mx,x);
}
cout<<"Yes"<<endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n,a[100010],mn;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
mn=a[n];
for(int i=n;i>=1;i--){
mn=min(a[i],mn);
if(a[i]-mn>1){
printf("No\n");
return 0;
}
}
printf("Yes\n");
} | ### Prompt
Construct a Cpp code solution to the problem outlined:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n,a[100010],mn;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
mn=a[n];
for(int i=n;i>=1;i--){
mn=min(a[i],mn);
if(a[i]-mn>1){
printf("No\n");
return 0;
}
}
printf("Yes\n");
}
``` |
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int N;
int maxn;
cin >> N;
cin >> maxn;
int a[N-1];
for (int i=1;i<N;i++){
cin >> a[i];
if(maxn-a[i]>1){
cout << "No";
return 0;
}
maxn = max(a[i],maxn);
}
cout << "Yes" << endl;
} | ### Prompt
Your challenge is to write a CPP solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int N;
int maxn;
cin >> N;
cin >> maxn;
int a[N-1];
for (int i=1;i<N;i++){
cin >> a[i];
if(maxn-a[i]>1){
cout << "No";
return 0;
}
maxn = max(a[i],maxn);
}
cout << "Yes" << endl;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=n-1;i>0;i--)
{
if(a[i]<a[i-1]-1)
return cout<<"No",0;
else
if(a[i]==a[i-1]-1)
a[i-1]--;
}
return cout<<"Yes",0;
} | ### Prompt
Please formulate a cpp solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=n-1;i>0;i--)
{
if(a[i]<a[i-1]-1)
return cout<<"No",0;
else
if(a[i]==a[i-1]-1)
a[i-1]--;
}
return cout<<"Yes",0;
}
``` |
#include <stdio.h>
#include <algorithm>
int main(){
int n,h,max=0;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&h);
if(max-1>h){
printf("No");
return 0;
}
else{
max=std::max(max,h);
}
}
printf("Yes");
} | ### Prompt
Develop a solution in CPP to the problem described below:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <stdio.h>
#include <algorithm>
int main(){
int n,h,max=0;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&h);
if(max-1>h){
printf("No");
return 0;
}
else{
max=std::max(max,h);
}
}
printf("Yes");
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n, h[100004];
int main() {
cin>>n;
for(int i = 0;i<n;i++) cin>>h[i];
for(int i = n-2;i>=0;i--){
if(h[i] <= h[i+1]) continue;
h[i]--;
if(h[i] > h[i+1]){
cout<<"No";
return 0;
}
}
cout<<"Yes";
return 0;
} | ### Prompt
Please formulate a CPP solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, h[100004];
int main() {
cin>>n;
for(int i = 0;i<n;i++) cin>>h[i];
for(int i = n-2;i>=0;i--){
if(h[i] <= h[i+1]) continue;
h[i]--;
if(h[i] > h[i+1]){
cout<<"No";
return 0;
}
}
cout<<"Yes";
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int n,a[100100];
int main(){
cin>>n;
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
if(a[i]<a[i-1]){cout<<"No";return 0;}
if(a[i]!=a[i-1]) a[i]--;
}
cout<<"Yes";
return 0;
} | ### Prompt
Please create a solution in cpp to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int n,a[100100];
int main(){
cin>>n;
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
if(a[i]<a[i-1]){cout<<"No";return 0;}
if(a[i]!=a[i-1]) a[i]--;
}
cout<<"Yes";
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
int maxn=0;
int k=0;
scanf("%d",&n);
int a[n];
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
if(a[i]>=maxn)
maxn=a[i];
else if(a[i]<maxn-1){
k=1;
}
}
if(k==1)
printf("No\n");
else
printf("Yes\n");
return 0;
} | ### Prompt
Develop a solution in cpp to the problem described below:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
int maxn=0;
int k=0;
scanf("%d",&n);
int a[n];
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
if(a[i]>=maxn)
maxn=a[i];
else if(a[i]<maxn-1){
k=1;
}
}
if(k==1)
printf("No\n");
else
printf("Yes\n");
return 0;
}
``` |
#include<stdio.h>
int main(){
int N;
scanf("%d",&N);
int H[N];
for(int i=0;i<N;i++){
scanf("%d",&H[i]);
}
for(int i=N-1;i>0;i--){
if(H[i]<H[i-1]-1){
printf("No\n");
return 0;
}
if(H[i]==H[i-1]-1)
H[i-1]--;
}
printf("Yes\n");
return 0;
} | ### Prompt
Create a solution in cpp for the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<stdio.h>
int main(){
int N;
scanf("%d",&N);
int H[N];
for(int i=0;i<N;i++){
scanf("%d",&H[i]);
}
for(int i=N-1;i>0;i--){
if(H[i]<H[i-1]-1){
printf("No\n");
return 0;
}
if(H[i]==H[i-1]-1)
H[i-1]--;
}
printf("Yes\n");
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
#define N 100005
int a[N];
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i];
a[0]--;
for(int i=1;i<n;i++)
if(a[i]<a[i-1])
{
cout<<"No\n";
return 0;
}
else a[i]=max(a[i-1],a[i]-1);
cout<<"Yes\n";
return 0;
} | ### Prompt
Your task is to create a CPP solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
#define N 100005
int a[N];
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i];
a[0]--;
for(int i=1;i<n;i++)
if(a[i]<a[i-1])
{
cout<<"No\n";
return 0;
}
else a[i]=max(a[i-1],a[i]-1);
cout<<"Yes\n";
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int n,h[100005];
int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i){
scanf("%d",&h[i]);
if(h[i]>h[i-1]&&h[i]>=0)h[i]--;
else if(h[i]<h[i-1]){puts("No");return 0;}
}
puts("Yes");
return 0;
}
| ### Prompt
Please create a solution in CPP to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int n,h[100005];
int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i){
scanf("%d",&h[i]);
if(h[i]>h[i-1]&&h[i]>=0)h[i]--;
else if(h[i]<h[i-1]){puts("No");return 0;}
}
puts("Yes");
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int dizi[100005];
int main(){
int a;
cin>>a;
for(int i=0;i<a;i++){
cin>>dizi[i];
}
for(int i=a-1;i>=1;i--){
if(dizi[i]<dizi[i-1]){
dizi[i-1]--;
}
if(dizi[i]<dizi[i-1]){
cout<<"No";
return 0;
}
}
cout<<"Yes";
} | ### Prompt
Please provide a cpp coded solution to the problem described below:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int dizi[100005];
int main(){
int a;
cin>>a;
for(int i=0;i<a;i++){
cin>>dizi[i];
}
for(int i=a-1;i>=1;i--){
if(dizi[i]<dizi[i-1]){
dizi[i-1]--;
}
if(dizi[i]<dizi[i-1]){
cout<<"No";
return 0;
}
}
cout<<"Yes";
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++) cin>>a[i];
for(int i=1;i<n;i++){
if(a[i-1]>a[i]){
a[i]++;
if(a[i-1]>a[i]){
cout<<"No"<<endl;
return 0;
}
}
}
cout<<"Yes"<<endl;
return 0;
} | ### Prompt
Please provide a cpp coded solution to the problem described below:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++) cin>>a[i];
for(int i=1;i<n;i++){
if(a[i-1]>a[i]){
a[i]++;
if(a[i-1]>a[i]){
cout<<"No"<<endl;
return 0;
}
}
}
cout<<"Yes"<<endl;
return 0;
}
``` |
#include<cstdio>
using namespace std;
int a[100050];
int main(){
int n;
scanf("%d",&n);
for (int i=1;i<=n;i++)
scanf("%d",&a[i]);
for (int i=2;i<=n;i++)
if (a[i]>a[i-1]) a[i]--;else
if (a[i]<a[i-1]) return printf("No\n"),0;
printf("Yes\n");
return 0;
} | ### Prompt
Your challenge is to write a cpp solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<cstdio>
using namespace std;
int a[100050];
int main(){
int n;
scanf("%d",&n);
for (int i=1;i<=n;i++)
scanf("%d",&a[i]);
for (int i=2;i<=n;i++)
if (a[i]>a[i-1]) a[i]--;else
if (a[i]<a[i-1]) return printf("No\n"),0;
printf("Yes\n");
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
int h;
for(int i=0;i<N;i++){
int H;
cin >> H;
if(i==0)h=H;
else{
if(H>h)H--;
if(H<h){
cout << "No" << endl;
return 0;
}
else h=H;
}
}
cout << "Yes" << endl;
return 0;
} | ### Prompt
In CPP, your task is to solve the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
int h;
for(int i=0;i<N;i++){
int H;
cin >> H;
if(i==0)h=H;
else{
if(H>h)H--;
if(H<h){
cout << "No" << endl;
return 0;
}
else h=H;
}
}
cout << "Yes" << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N,H;
cin >> N >> H;
int bi = H;
for (int i=0; i<N-1; i++) {
cin >> H;
if (bi > H+1) {
cout << "No" << endl;
return 0;
}
bi = max(bi,H);
}
cout << "Yes" << endl;
return 0;
} | ### Prompt
Develop a solution in Cpp to the problem described below:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int N,H;
cin >> N >> H;
int bi = H;
for (int i=0; i<N-1; i++) {
cin >> H;
if (bi > H+1) {
cout << "No" << endl;
return 0;
}
bi = max(bi,H);
}
cout << "Yes" << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,d=1; cin>>n;
int h[n];for(int i=0;i<n;i++) cin>>h[i];
for(int i=n-1;i>0;i--){
if(h[i]+1==h[i-1]) h[i-1]--;
else if(h[i]+1<h[i-1]) d=0;
}
if(d) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
| ### Prompt
In CPP, your task is to solve the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,d=1; cin>>n;
int h[n];for(int i=0;i<n;i++) cin>>h[i];
for(int i=n-1;i>0;i--){
if(h[i]+1==h[i-1]) h[i-1]--;
else if(h[i]+1<h[i-1]) d=0;
}
if(d) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
``` |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll h[100001];
int main()
{
ll n;
cin>>n;
for(ll i=0;i<n;i++)
cin>>h[i];
ll m=h[0]-1;
for(ll i=1;i<n;i++){
if((h[i]<m)&&(h[i]<(m+1))){
cout<<"No";
return 0;
}
m=max(m,h[i]-1);
}
cout<<"Yes";
} | ### Prompt
Please formulate a cpp solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll h[100001];
int main()
{
ll n;
cin>>n;
for(ll i=0;i<n;i++)
cin>>h[i];
ll m=h[0]-1;
for(ll i=1;i<n;i++){
if((h[i]<m)&&(h[i]<(m+1))){
cout<<"No";
return 0;
}
m=max(m,h[i]-1);
}
cout<<"Yes";
}
``` |
#include<iostream>
using namespace std;
string solve(){
int N,H,H2;
cin>>N;
cin>>H;
for(int i=0;i<N-1;i++){
cin>>H2;
if(H2<H){
return "No";
}
if(H2>H){
H=H2-1;
}else{
H=H2;
}
}
return "Yes";
}
int main(){
string ans=solve();
cout<<ans<<endl;
return 0;
}
| ### Prompt
Please provide a Cpp coded solution to the problem described below:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<iostream>
using namespace std;
string solve(){
int N,H,H2;
cin>>N;
cin>>H;
for(int i=0;i<N-1;i++){
cin>>H2;
if(H2<H){
return "No";
}
if(H2>H){
H=H2-1;
}else{
H=H2;
}
}
return "Yes";
}
int main(){
string ans=solve();
cout<<ans<<endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
int h, H;
cin >> H;
H--;
for (int i=1; i<N; i++) {
cin >> h;
if(H - h >= 1){
cout << "No" <<endl;
return 0;;
}
if(h > H)
H = h - 1;
}
cout <<"Yes"<<endl;
}
| ### Prompt
Please formulate a cpp solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
int h, H;
cin >> H;
H--;
for (int i=1; i<N; i++) {
cin >> h;
if(H - h >= 1){
cout << "No" <<endl;
return 0;;
}
if(h > H)
H = h - 1;
}
cout <<"Yes"<<endl;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int n,a[100010],f,ff;
int main(){
cin>>n;
for (int i=0;i<n;i++) cin>>a[i];
f=a[0]-1;
for (int i=1;i<n;i++)
if (a[i]>f)
f=a[i]-1;
else if (a[i]!=f)
ff=1;
if (ff==1)
cout<<"No"<<endl;
else
cout<<"Yes"<<endl;
return 0;
} | ### Prompt
Your task is to create a CPP solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int n,a[100010],f,ff;
int main(){
cin>>n;
for (int i=0;i<n;i++) cin>>a[i];
f=a[0]-1;
for (int i=1;i<n;i++)
if (a[i]>f)
f=a[i]-1;
else if (a[i]!=f)
ff=1;
if (ff==1)
cout<<"No"<<endl;
else
cout<<"Yes"<<endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,a[100005];
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=n-1;i>0;i--)
if (a[i-1]-a[i]>1)
{
cout<<"No";
return 0;
}
else if (a[i-1]-a[i]==1)
a[i-1]--;
cout<<"Yes";
return 0;
}
| ### Prompt
Create a solution in cpp for the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,a[100005];
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=n-1;i>0;i--)
if (a[i-1]-a[i]>1)
{
cout<<"No";
return 0;
}
else if (a[i-1]-a[i]==1)
a[i-1]--;
cout<<"Yes";
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n];
for(int &i : arr) cin >> i;
for(int i = n-2, _min = arr[n-1]; i >= 0; i--) {
if(arr[i]-_min > 1) return cout << "No", 0;
_min = min(_min, arr[i]);
}
cout << "Yes";
}
| ### Prompt
Generate a CPP solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n];
for(int &i : arr) cin >> i;
for(int i = n-2, _min = arr[n-1]; i >= 0; i--) {
if(arr[i]-_min > 1) return cout << "No", 0;
_min = min(_min, arr[i]);
}
cout << "Yes";
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, highest = 0;
cin >> n;
for (int i = 0; i < n; i++) {
int h;
cin >> h;
if (h > highest) highest = h;
if (highest > h + 1) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
}
| ### Prompt
Please provide a Cpp coded solution to the problem described below:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, highest = 0;
cin >> n;
for (int i = 0; i < n; i++) {
int h;
cin >> h;
if (h > highest) highest = h;
if (highest > h + 1) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int h[100100],n;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",&h[i]);
h[n+1]=2100000000;
int maxx=-1;
for(int i=1;i<=n;i++){
maxx=max(maxx,h[i]);
if(maxx-h[i]>1){
printf("No");
return 0;
}
}
printf("Yes");
return 0;
} | ### Prompt
Please create a solution in CPP to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int h[100100],n;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",&h[i]);
h[n+1]=2100000000;
int maxx=-1;
for(int i=1;i<=n;i++){
maxx=max(maxx,h[i]);
if(maxx-h[i]>1){
printf("No");
return 0;
}
}
printf("Yes");
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n;
int arr[100005];
int main()
{
cin >> n;
for(int i=0;i<n;i++)
cin >> arr[i];
for(int i=n-2;i>=0;i--)
{
if(arr[i]>arr[i+1]) arr[i]--;
}
bool ok=1;
for(int i=1;i<n;i++)
ok&=(arr[i]>=arr[i-1]);
cout << (ok?"Yes":"No") << endl;
} | ### Prompt
Generate a CPP solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
int arr[100005];
int main()
{
cin >> n;
for(int i=0;i<n;i++)
cin >> arr[i];
for(int i=n-2;i>=0;i--)
{
if(arr[i]>arr[i+1]) arr[i]--;
}
bool ok=1;
for(int i=1;i<n;i++)
ok&=(arr[i]>=arr[i-1]);
cout << (ok?"Yes":"No") << endl;
}
``` |
#include <iostream>
using namespace std;
int a[100007];
int main(){
int n;
cin >> n;
for(int i = 0;i < n;i++){
cin >> a[i];
}
for(int i = n-1;i>0;i--){
if(a[i]<a[i-1]){
a[i-1]--;
}
if(a[i]<a[i-1]){
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
} | ### Prompt
Please formulate a CPP solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <iostream>
using namespace std;
int a[100007];
int main(){
int n;
cin >> n;
for(int i = 0;i < n;i++){
cin >> a[i];
}
for(int i = n-1;i>0;i--){
if(a[i]<a[i-1]){
a[i-1]--;
}
if(a[i]<a[i-1]){
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int n,h[100010];
int main()
{
ios::sync_with_stdio(false);
cin>>n;
for(int i=1;i<=n;i++)
cin>>h[i];
for(int i=n;i>1;--i)
{
if(h[i-1]-h[i]>1)
{
cout<<"No";
return 0;
}
if(h[i-1]-h[i]>0)
h[i-1]-=1;
}
cout<<"Yes";
return 0;
} | ### Prompt
Please provide a CPP coded solution to the problem described below:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int n,h[100010];
int main()
{
ios::sync_with_stdio(false);
cin>>n;
for(int i=1;i<=n;i++)
cin>>h[i];
for(int i=n;i>1;--i)
{
if(h[i-1]-h[i]>1)
{
cout<<"No";
return 0;
}
if(h[i-1]-h[i]>0)
h[i-1]-=1;
}
cout<<"Yes";
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int ma = -1;
bool isok = true;
for(int i=0;i<n;i++)
{
int a;
cin>>a;
if(ma-a>1)
{
isok = false;
break;
}
ma = max(a,ma);
}
if(isok)
{
cout<<"Yes\n";
}
else
{
cout<<"No\n";
}
return 0;
} | ### Prompt
Create a solution in Cpp for the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int ma = -1;
bool isok = true;
for(int i=0;i<n;i++)
{
int a;
cin>>a;
if(ma-a>1)
{
isok = false;
break;
}
ma = max(a,ma);
}
if(isok)
{
cout<<"Yes\n";
}
else
{
cout<<"No\n";
}
return 0;
}
``` |
#include<iostream>
using namespace std;
int a[100005];
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<n;i++){
if(a[i]>a[i+1]){
if(a[i]-a[i+1]!=1||a[i-1]>a[i]-1){
cout<<"No";return 0;
}
}
if(a[i-1]<a[i])a[i]--;
}
cout<<"Yes";
return 0;
} | ### Prompt
Your challenge is to write a CPP solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<iostream>
using namespace std;
int a[100005];
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<n;i++){
if(a[i]>a[i+1]){
if(a[i]-a[i+1]!=1||a[i-1]>a[i]-1){
cout<<"No";return 0;
}
}
if(a[i-1]<a[i])a[i]--;
}
cout<<"Yes";
return 0;
}
``` |
#include<cstdio>
#include<iostream>
using namespace std;
int n;
int a[100005];
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=n;i>=1;i--){
if(a[i]<a[i-1]){
a[i-1]-=1;
if(a[i]<a[i-1]){
cout<<"No";
return 0;
}
}
}
cout<<"Yes";
return 0;
} | ### Prompt
In cpp, your task is to solve the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<cstdio>
#include<iostream>
using namespace std;
int n;
int a[100005];
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=n;i>=1;i--){
if(a[i]<a[i-1]){
a[i-1]-=1;
if(a[i]<a[i-1]){
cout<<"No";
return 0;
}
}
}
cout<<"Yes";
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int a[100001];
int main() {
int i,j,n,m,t,k;
cin>>n;
for(i=1;i<=n;i++)
cin>>a[i];
for(i=n;i>1;i--)
{
if(a[i-1]>a[i]){a[i-1]--;
if(a[i-1]>a[i])
{cout<<"No";
return 0;
}
}
}
cout<<"Yes";
} | ### Prompt
Construct a cpp code solution to the problem outlined:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int a[100001];
int main() {
int i,j,n,m,t,k;
cin>>n;
for(i=1;i<=n;i++)
cin>>a[i];
for(i=n;i>1;i--)
{
if(a[i-1]>a[i]){a[i-1]--;
if(a[i-1]>a[i])
{cout<<"No";
return 0;
}
}
}
cout<<"Yes";
}
``` |
#include <iostream>
using namespace std;
int main(){
int n;
cin >> n;
bool f=true;
int hb=0;
for(int i=0; i<n; ++i){
int h;
cin >> h;
if(h<hb){
f=false;
}else if(hb==h){
hb=h;
}else {
hb=h-1;
}
}
if(f) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}
| ### Prompt
Construct a Cpp code solution to the problem outlined:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <iostream>
using namespace std;
int main(){
int n;
cin >> n;
bool f=true;
int hb=0;
for(int i=0; i<n; ++i){
int h;
cin >> h;
if(h<hb){
f=false;
}else if(hb==h){
hb=h;
}else {
hb=h-1;
}
}
if(f) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}
``` |
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main() {
int N;
cin >> N;
long long H[100010];
int max = 0;
for (int i = 1; i <= N; i++) {
cin >> H[i];
if (max < H[i])max = H[i];
else if (max - H[i] >= 2) { cout << "No"; return 0; }
}
cout << "Yes";
} | ### Prompt
Please provide a cpp coded solution to the problem described below:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main() {
int N;
cin >> N;
long long H[100010];
int max = 0;
for (int i = 1; i <= N; i++) {
cin >> H[i];
if (max < H[i])max = H[i];
else if (max - H[i] >= 2) { cout << "No"; return 0; }
}
cout << "Yes";
}
``` |
#include<bits/stdc++.h>
using namespace std;
int n,h[2];
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&h[1]);
if(h[1]<h[0]){puts("No");return 0;}
if(h[1]>h[0])h[1]--;
h[0]=h[1];
}
puts("Yes");
} | ### Prompt
Develop a solution in CPP to the problem described below:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int n,h[2];
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&h[1]);
if(h[1]<h[0]){puts("No");return 0;}
if(h[1]>h[0])h[1]--;
h[0]=h[1];
}
puts("Yes");
}
``` |
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int n;
cin >> n;
int a[n];
for(int i=0;i<n;i++) cin >> a[i];
bool ans=true;
int s=0;
for(int i=0;i<n;i++){
if(s-a[i]>=2) ans=false;
s=max(s,a[i]);
}
cout << (ans?"Yes":"No") << endl;
} | ### Prompt
Please provide a Cpp coded solution to the problem described below:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int n;
cin >> n;
int a[n];
for(int i=0;i<n;i++) cin >> a[i];
bool ans=true;
int s=0;
for(int i=0;i<n;i++){
if(s-a[i]>=2) ans=false;
s=max(s,a[i]);
}
cout << (ans?"Yes":"No") << endl;
}
``` |
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
if(n==1){
cout<<"Yes";
return 0;
}
int a,b;
cin>>a;
for(int i=2;i<=n;i++){
cin>>b;
if(a-b==1){
b++;
}
if(a-b>1){
cout<<"No";
return 0;
}
a=b;
}
cout<<"Yes";
return 0;
} | ### Prompt
Create a solution in Cpp for the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
if(n==1){
cout<<"Yes";
return 0;
}
int a,b;
cin>>a;
for(int i=2;i<=n;i++){
cin>>b;
if(a-b==1){
b++;
}
if(a-b>1){
cout<<"No";
return 0;
}
a=b;
}
cout<<"Yes";
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n;
cin>>n;
long long h[n];
for (long long i=0;i<n;i++) cin>>h[i];
for (long long i=n-1;i>0;i--){
if (h[i]<h[i-1]-1){
cout<<"No";
return 0;
}
else if (h[i]==h[i-1]-1) h[i-1]=h[i-1]-1;
}
cout<<"Yes";
}
| ### Prompt
Generate a CPP solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n;
cin>>n;
long long h[n];
for (long long i=0;i<n;i++) cin>>h[i];
for (long long i=n-1;i>0;i--){
if (h[i]<h[i-1]-1){
cout<<"No";
return 0;
}
else if (h[i]==h[i-1]-1) h[i-1]=h[i-1]-1;
}
cout<<"Yes";
}
``` |
#include <iostream>
using namespace std;
int main(){
int n;
long long h,a;
bool tf=true;
cin>>n>>a;
for(int i=1;i<n;i++){
cin>>h;
if(h==a){
a=h;
}else if(a<h){
a=h-1;
}else{
tf=false;
break;
}
}
if(tf){
cout<<"Yes"<<endl;
}else{
cout<<"No"<<endl;
}
return 0;
} | ### Prompt
Create a solution in CPP for the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <iostream>
using namespace std;
int main(){
int n;
long long h,a;
bool tf=true;
cin>>n>>a;
for(int i=1;i<n;i++){
cin>>h;
if(h==a){
a=h;
}else if(a<h){
a=h-1;
}else{
tf=false;
break;
}
}
if(tf){
cout<<"Yes"<<endl;
}else{
cout<<"No"<<endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=n-1;i>0;i--){
if((a[i-1]-a[i])>1){
cout<<"No"<<endl;
return 0;
}
else
if(a[i-1]-a[i]==1){
a[i-1]--;
}
}
cout<<"Yes"<<endl;
return 0;
}
| ### Prompt
Construct a CPP code solution to the problem outlined:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=n-1;i>0;i--){
if((a[i-1]-a[i])>1){
cout<<"No"<<endl;
return 0;
}
else
if(a[i-1]-a[i]==1){
a[i-1]--;
}
}
cout<<"Yes"<<endl;
return 0;
}
``` |
#include <iostream>
using namespace std;
int main() {
int N;
cin >> N;
int tmp = 0;
bool flag = true;
for (int n = 0; n < N; n++) {
int H;
cin >> H;
if (tmp <= H - 1) tmp = H - 1;
else if (tmp == H) tmp = H;
else flag = false;
}
if (flag) cout << "Yes\n";
else cout << "No\n";
} | ### Prompt
Construct a Cpp code solution to the problem outlined:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <iostream>
using namespace std;
int main() {
int N;
cin >> N;
int tmp = 0;
bool flag = true;
for (int n = 0; n < N; n++) {
int H;
cin >> H;
if (tmp <= H - 1) tmp = H - 1;
else if (tmp == H) tmp = H;
else flag = false;
}
if (flag) cout << "Yes\n";
else cout << "No\n";
}
``` |
#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
int h[n];
for(int i=0;i<n;i++)cin>>h[i];
h[0]--;
for(int i=1;i<n;i++){
if(h[i]>h[i-1])h[i]--;
if(h[i]<h[i-1]){
cout<<"No";
return 0;
}
}
cout<<"Yes";
}
| ### Prompt
Please create a solution in CPP to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
int h[n];
for(int i=0;i<n;i++)cin>>h[i];
h[0]--;
for(int i=1;i<n;i++){
if(h[i]>h[i-1])h[i]--;
if(h[i]<h[i-1]){
cout<<"No";
return 0;
}
}
cout<<"Yes";
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin>>n;
int a[100004];
for(int i = 0;i<n;i++) cin>>a[i];
int cur = a[0];
for(int i = 1;i<n;i++)
if(cur-1 <= a[i]){
cur = max(cur, a[i]);
continue;
}
else{
cout<<"No";
return 0;
}
cout<<"Yes";
return 0;
} | ### Prompt
Please create a solution in cpp to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin>>n;
int a[100004];
for(int i = 0;i<n;i++) cin>>a[i];
int cur = a[0];
for(int i = 1;i<n;i++)
if(cur-1 <= a[i]){
cur = max(cur, a[i]);
continue;
}
else{
cout<<"No";
return 0;
}
cout<<"Yes";
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int max_h = 0;
for(int i = 0; i < n; i++){
int h;
cin >> h;
if(h > max_h){ max_h = h; }
if(max_h - h > 1) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
} | ### Prompt
Your challenge is to write a CPP solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int max_h = 0;
for(int i = 0; i < n; i++){
int h;
cin >> h;
if(h > max_h){ max_h = h; }
if(max_h - h > 1) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n;
long long h[100001];
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>h[i];
}
for(int i=n;i>1;i--)
{
if(h[i-1]-1>h[i])
{
cout<<"No"<<endl;
return 0;
}
else if(h[i-1]-1==h[i])
{
h[i-1]--;
}
}
puts("Yes");
} | ### Prompt
Generate a CPP solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
long long h[100001];
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>h[i];
}
for(int i=n;i>1;i--)
{
if(h[i-1]-1>h[i])
{
cout<<"No"<<endl;
return 0;
}
else if(h[i-1]-1==h[i])
{
h[i-1]--;
}
}
puts("Yes");
}
``` |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll i,n;
cin >> n;
ll h[n];
for(i=0;i<n;i++) cin >> h[i];
for(i=1;i<n;i++){
if(h[i]>h[i-1]) h[i]--;
if(h[i]<h[i-1]){
puts("No");
exit(0);
}
}
puts("Yes");
}
| ### Prompt
Develop a solution in CPP to the problem described below:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll i,n;
cin >> n;
ll h[n];
for(i=0;i<n;i++) cin >> h[i];
for(i=1;i<n;i++){
if(h[i]>h[i-1]) h[i]--;
if(h[i]<h[i-1]){
puts("No");
exit(0);
}
}
puts("Yes");
}
``` |
#include<bits/stdc++.h>
using namespace std;
int a[100010];
vector <int>b[100010];
int main()
{
bool check1=true;
int n;
cin>>n;
int maxx=0;
for (int i=1;i<=n;i++)
{
cin>>a[i];
if (maxx-a[i]>1) check1=false;
maxx=max(maxx,a[i]);
}
if (check1)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
} | ### Prompt
Please create a solution in CPP to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int a[100010];
vector <int>b[100010];
int main()
{
bool check1=true;
int n;
cin>>n;
int maxx=0;
for (int i=1;i<=n;i++)
{
cin>>a[i];
if (maxx-a[i]>1) check1=false;
maxx=max(maxx,a[i]);
}
if (check1)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
bool ans = true;
long long n, a[1000000], mx;
int main() {
cin>>n;
for (int i = 0; i < n; i++) {
cin>>a[i];
if (mx-1 > a[i]) ans = false;
mx = max(mx,a[i]);
}
if (ans) cout<<"Yes";
else cout<<"No";
}
| ### Prompt
Create a solution in Cpp for the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool ans = true;
long long n, a[1000000], mx;
int main() {
cin>>n;
for (int i = 0; i < n; i++) {
cin>>a[i];
if (mx-1 > a[i]) ans = false;
mx = max(mx,a[i]);
}
if (ans) cout<<"Yes";
else cout<<"No";
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
vector<int> h(n);
for (int i=0; i<n; i++) cin>>h[i];
int max_h=0;
bool ans=true;
for (int j=0; j<n; j++){
if (max_h>=h[j]+2) ans=false;
max_h=max(max_h,h[j]);
}
cout<<(ans ? "Yes" : "No")<<endl;
} | ### Prompt
Construct a CPP code solution to the problem outlined:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
vector<int> h(n);
for (int i=0; i<n; i++) cin>>h[i];
int max_h=0;
bool ans=true;
for (int j=0; j<n; j++){
if (max_h>=h[j]+2) ans=false;
max_h=max(max_h,h[j]);
}
cout<<(ans ? "Yes" : "No")<<endl;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int n;
cin>>n;
long long int a[n],i,min=INT_MAX;
for(i=0;i<n;i++)
cin>>a[i];
for(i=(n-1);i>=1;i--)
if(a[i]<a[i-1])
a[i-1]--;
for(i=0;i<(n-1);i++)
if(a[i]>a[i+1])
{
cout<<"No"<<"\n";
return 0;
}
cout<<"Yes"<<"\n";
return 0;
} | ### Prompt
In Cpp, your task is to solve the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int n;
cin>>n;
long long int a[n],i,min=INT_MAX;
for(i=0;i<n;i++)
cin>>a[i];
for(i=(n-1);i>=1;i--)
if(a[i]<a[i-1])
a[i-1]--;
for(i=0;i<(n-1);i++)
if(a[i]>a[i+1])
{
cout<<"No"<<"\n";
return 0;
}
cout<<"Yes"<<"\n";
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
long long n,i,h[100010];
int main(){
cin>>n;
for(i=1;i<=n;i++)cin>>h[i];
for(i=1;i<=n;i++){
if(h[i]<h[i-1]){
cout<<"No";
return 0;
}
else
if(h[i]>h[i-1])h[i]--;
}
cout<<"Yes";
return 0;
} | ### Prompt
Develop a solution in CPP to the problem described below:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
long long n,i,h[100010];
int main(){
cin>>n;
for(i=1;i<=n;i++)cin>>h[i];
for(i=1;i<=n;i++){
if(h[i]<h[i-1]){
cout<<"No";
return 0;
}
else
if(h[i]>h[i-1])h[i]--;
}
cout<<"Yes";
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
long long n,h[100005];
int main(){
cin>>n;
for(int i=1;i<=n;i++) cin>>h[i];
for(int i=2;i<=n;i++)
{
if(h[i-1]-h[i]>1) {cout<<"No";return 0;}
else if(h[i-1]-h[i]==1) h[i]++;
}
cout<<"Yes";
return 0;
} | ### Prompt
Please formulate a Cpp solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
long long n,h[100005];
int main(){
cin>>n;
for(int i=1;i<=n;i++) cin>>h[i];
for(int i=2;i<=n;i++)
{
if(h[i-1]-h[i]>1) {cout<<"No";return 0;}
else if(h[i-1]-h[i]==1) h[i]++;
}
cout<<"Yes";
return 0;
}
``` |
#include <iostream>
using namespace std;
int main(){
int n,h=0,next;
cin>>n;
bool flag=true;
for(int i=0;i<n;i++){
cin >> next;
if( h > next)flag=false;
else if(h < next)next--;
h=next;
}
if(flag)cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
} | ### Prompt
In CPP, your task is to solve the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <iostream>
using namespace std;
int main(){
int n,h=0,next;
cin>>n;
bool flag=true;
for(int i=0;i<n;i++){
cin >> next;
if( h > next)flag=false;
else if(h < next)next--;
h=next;
}
if(flag)cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}
``` |
#include <iostream>
using namespace std;
int main(void){
int n, l, h;
int ans=1;
cin >> n;
l = 0;
for (int i=0; i<n; i++){
cin >> h;
if (l>h) ans=0;
l = l==h?h:h-1;
}
cout << (ans?"Yes":"No") << endl;
return 0;
}
| ### Prompt
Please formulate a CPP solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <iostream>
using namespace std;
int main(void){
int n, l, h;
int ans=1;
cin >> n;
l = 0;
for (int i=0; i<n; i++){
cin >> h;
if (l>h) ans=0;
l = l==h?h:h-1;
}
cout << (ans?"Yes":"No") << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
cin >> n;
long long h[n];
string ans = "Yes";
for(int i = 0; i < n; i++) cin >> h[i];
for(int i = n-2; i > 0; i--){
if(h[i]>h[i+1]) h[i]--;
if(h[i]>h[i+1]){
ans = "No";
}
}
cout << ans << endl;
}
| ### Prompt
Develop a solution in CPP to the problem described below:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
cin >> n;
long long h[n];
string ans = "Yes";
for(int i = 0; i < n; i++) cin >> h[i];
for(int i = n-2; i > 0; i--){
if(h[i]>h[i+1]) h[i]--;
if(h[i]>h[i+1]){
ans = "No";
}
}
cout << ans << endl;
}
``` |
// abc136c.cpp : Build Stairs
#include <bits/stdc++.h>
using namespace std;
#define in(x) cin>>(x)
int main(){
int n; in(n);
int a = -1;
bool f = true;
for(int i=0;i<n;i++){
int h; in(h);
if(a>h){ f = false; break; }
else if(a<h) a = --h;
}
cout<< (f? "Yes":"No") <<endl;
} | ### Prompt
Your task is to create a CPP solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
// abc136c.cpp : Build Stairs
#include <bits/stdc++.h>
using namespace std;
#define in(x) cin>>(x)
int main(){
int n; in(n);
int a = -1;
bool f = true;
for(int i=0;i<n;i++){
int h; in(h);
if(a>h){ f = false; break; }
else if(a<h) a = --h;
}
cout<< (f? "Yes":"No") <<endl;
}
``` |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main(){
int count=0;
int N;
cin>>N>>count;
rep(i,N-1){
int a;
cin>>a;
if(count>a+1){
cout<<"No";
return 0;
}
if(count<a)
count=a;
}
cout<<"Yes";
} | ### Prompt
Your challenge is to write a cpp solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main(){
int count=0;
int N;
cin>>N>>count;
rep(i,N-1){
int a;
cin>>a;
if(count>a+1){
cout<<"No";
return 0;
}
if(count<a)
count=a;
}
cout<<"Yes";
}
``` |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;cin>>n;
int a[n];
for(int i=0;i<n;i++)cin>>a[i];
int f=1;
a[0]=a[0]-1;
for(int i=1;i<n;i++){
if(a[i-1]<a[i])a[i]=a[i]-1;
}
for(int i=1;i<n;i++){
if(a[i-1]<=a[i]);
else f=0;
}
if(f)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
} | ### Prompt
Your challenge is to write a CPP solution to the following problem:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;cin>>n;
int a[n];
for(int i=0;i<n;i++)cin>>a[i];
int f=1;
a[0]=a[0]-1;
for(int i=1;i<n;i++){
if(a[i-1]<a[i])a[i]=a[i]-1;
}
for(int i=1;i<n;i++){
if(a[i-1]<=a[i]);
else f=0;
}
if(f)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
vector<int> h(n);
for(int i=0;i<n;i++) cin >> h[i];
h[0]--;
for(int i=1;i<n;i++){
if(h[i]==h[i-1]) continue;
if(h[i-1]<h[i]) h[i]--;
else{
cout << "No";
return 0;
}
}
cout << "Yes";
} | ### Prompt
Develop a solution in CPP to the problem described below:
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
* Decrease the height of the square by 1.
* Do nothing.
Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq H_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
H_1 H_2 ... H_N
Output
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print `Yes`; otherwise, print `No`.
Examples
Input
5
1 2 1 1 3
Output
Yes
Input
4
1 3 2 1
Output
No
Input
5
1 2 3 4 5
Output
Yes
Input
1
1000000000
Output
Yes
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
vector<int> h(n);
for(int i=0;i<n;i++) cin >> h[i];
h[0]--;
for(int i=1;i<n;i++){
if(h[i]==h[i-1]) continue;
if(h[i-1]<h[i]) h[i]--;
else{
cout << "No";
return 0;
}
}
cout << "Yes";
}
``` |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.