output
stringlengths 52
181k
| instruction
stringlengths 296
182k
|
---|---|
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
int a[100005];
cin >> n;
a[0]=0;
int f=0;
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
if(a[i]+1==a[i-1]){
a[i]++;
}
else if(a[i]+1<a[i-1]){
f=1;
}
}
if(f==0)printf("Yes");
else printf("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>
using namespace std;
int main()
{
int n;
int a[100005];
cin >> n;
a[0]=0;
int f=0;
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
if(a[i]+1==a[i-1]){
a[i]++;
}
else if(a[i]+1<a[i-1]){
f=1;
}
}
if(f==0)printf("Yes");
else printf("No");
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int a[100010],n;
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;++i) scanf("%d",&a[i]);
for(int i=n-1;i>=1;--i)
if(a[i]>a[i+1]) --a[i];
for(int i=1;i<n;++i)
if(a[i]>a[i+1]) {
printf("No");
return 0;
}
printf("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 a[100010],n;
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;++i) scanf("%d",&a[i]);
for(int i=n-1;i>=1;--i)
if(a[i]>a[i+1]) --a[i];
for(int i=1;i<n;++i)
if(a[i]>a[i+1]) {
printf("No");
return 0;
}
printf("Yes");
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int n,a[100010];
int main() {
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=1;i<n;i++)
if(a[i]>a[i+1]) {
if(a[i]-a[i+1]>=2) {
printf("No");
return 0;
}
a[i+1]++;
}
printf("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<bits/stdc++.h>
using namespace std;
int n,a[100010];
int main() {
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=1;i<n;i++)
if(a[i]>a[i+1]) {
if(a[i]-a[i+1]>=2) {
printf("No");
return 0;
}
a[i+1]++;
}
printf("Yes");
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int arr[100007];
int main()
{
int n;
cin>>n;
for( int i=1;i<=n;i++ )
cin>>arr[i], arr[i]= (arr[i]-1>=arr[i-1])?arr[i]-1:arr[i];
bool f= 1;
for( int i=2;i<=n;i++ )
if( arr[i]<arr[i-1] )
f= 0;
if(f)
cout<<"Yes\n";
else
cout<<"No\n";
} | ### 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 arr[100007];
int main()
{
int n;
cin>>n;
for( int i=1;i<=n;i++ )
cin>>arr[i], arr[i]= (arr[i]-1>=arr[i-1])?arr[i]-1:arr[i];
bool f= 1;
for( int i=2;i<=n;i++ )
if( arr[i]<arr[i-1] )
f= 0;
if(f)
cout<<"Yes\n";
else
cout<<"No\n";
}
``` |
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N, M, H;
cin >> N;
bool cond{true};
while (cond && cin >> H) {
M = max(M, H);
cond &= (M - H <= 1);
}
cout << (cond ? "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 <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N, M, H;
cin >> N;
bool cond{true};
while (cond && cin >> H) {
M = max(M, H);
cond &= (M - H <= 1);
}
cout << (cond ? "Yes" : "No") << endl;
}
``` |
#include<iostream>
using namespace std;
int n,h[100000],maxn=-1;
int main(void){
cin>>n;
for(int i=0;i<n;i++)cin>>h[i];
for(int i=0;i<n;i++){
maxn=max(maxn,h[i]);
if(maxn-h[i]>=2){cout<<"No";return 0;}
}
cout<<"Yes";
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<iostream>
using namespace std;
int n,h[100000],maxn=-1;
int main(void){
cin>>n;
for(int i=0;i<n;i++)cin>>h[i];
for(int i=0;i<n;i++){
maxn=max(maxn,h[i]);
if(maxn-h[i]>=2){cout<<"No";return 0;}
}
cout<<"Yes";
return 0;
}
``` |
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int n,a,b;
scanf("%d",&n);
a=0;
while(n--)
{
scanf("%d",&b);
if(b<a)
{
printf("No");
return 0;
}
a=(b-1>=a)?b-1:b;
}
printf("Yes");
return 0;
} | ### 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 <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int n,a,b;
scanf("%d",&n);
a=0;
while(n--)
{
scanf("%d",&b);
if(b<a)
{
printf("No");
return 0;
}
a=(b-1>=a)?b-1:b;
}
printf("Yes");
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main(){
int N; cin >> N;
int pre=0;
for(int i=0; i<N; i++){
int h; cin >> h;
if(pre<h) pre=h-1;
else if(pre==h) pre=h;
else{
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << 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 N; cin >> N;
int pre=0;
for(int i=0; i<N; i++){
int h; cin >> h;
if(pre<h) pre=h-1;
else if(pre==h) pre=h;
else{
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int main(){
unsigned long N, H;
cin >> N >> H;
for(unsigned long i = 1, h; i < N; ++i){
cin >> h;
if(H > h)return 0 & puts("No");
if(H < h)--h;
swap(H, h);
}
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 main(){
unsigned long N, H;
cin >> N >> H;
for(unsigned long i = 1, h; i < N; ++i){
cin >> h;
if(H > h)return 0 & puts("No");
if(H < h)--h;
swap(H, h);
}
puts("Yes");
}
``` |
#include <iostream>
using namespace std;
int main() {
int h,s=0;
cin>>h;
while(cin>>h){
if(h>s){
s=h;
}else if(h<s-1){
cout << "No";
return 0;
}
}
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 <iostream>
using namespace std;
int main() {
int h,s=0;
cin>>h;
while(cin>>h){
if(h>s){
s=h;
}else if(h<s-1){
cout << "No";
return 0;
}
}
cout << "Yes";
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n;
int h,k;
bool ok=1;
int main(){
cin>>n;n--;
cin>>h;h--;
while(n--){
cin>>k;
if(k<h){cout<<"No";return 0;}
if(k>=h+1)h=k-1;
}
cout<<"Yes"<<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 n;
int h,k;
bool ok=1;
int main(){
cin>>n;n--;
cin>>h;h--;
while(n--){
cin>>k;
if(k<h){cout<<"No";return 0;}
if(k>=h+1)h=k-1;
}
cout<<"Yes"<<endl;
}
``` |
#include <iostream>
using namespace std;
int main()
{
int N;
cin >> N;
int H;
cin >> H;
int i = 1;
for (; i < N; ++i)
{
int _H;
cin >> _H;
if (_H < H)
break;
H = (H < _H ? _H - 1 : _H);
}
cout << (N == i ? "Yes" : "No");
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;
int H;
cin >> H;
int i = 1;
for (; i < N; ++i)
{
int _H;
cin >> _H;
if (_H < H)
break;
H = (H < _H ? _H - 1 : _H);
}
cout << (N == i ? "Yes" : "No");
return 0;
}
``` |
#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.at(i);
string s="Yes";
int k=0;
for(int i=0;i<n;i++){
if(k>h.at(i)+1){
s="No";
break;
}
k=max(k,h.at(i));
}
cout << s << 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
#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.at(i);
string s="Yes";
int k=0;
for(int i=0;i<n;i++){
if(k>h.at(i)+1){
s="No";
break;
}
k=max(k,h.at(i));
}
cout << s << endl;
}
``` |
#include<bits/stdc++.h>
using namespace std;
#define M 100005
int a[M];
int main(){
int n;
scanf("%d",&n);
for(int i=1;i<=n;++i)scanf("%d",&a[i]);
for(int i=1;i<=n;++i)if(a[i]>a[i-1])a[i]--;
for(int i=1;i<n;++i)if(a[i]>a[i+1]){
puts("No");
return 0;
}
puts("Yes");
} | ### 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;
#define M 100005
int a[M];
int main(){
int n;
scanf("%d",&n);
for(int i=1;i<=n;++i)scanf("%d",&a[i]);
for(int i=1;i<=n;++i)if(a[i]>a[i-1])a[i]--;
for(int i=1;i<n;++i)if(a[i]>a[i+1]){
puts("No");
return 0;
}
puts("Yes");
}
``` |
#include <cstdio>
using namespace std;
int N, H0, H1;
int main() {
scanf("%d", &N);
for(int i = 0; i < N; i++) {
scanf("%d", &H1);
if(i == 0) H0 = H1;
if(H0 > H1) {printf("No"); return 0;}
if(H0 < H1) H1--;
H0 = H1;
}
printf("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 <cstdio>
using namespace std;
int N, H0, H1;
int main() {
scanf("%d", &N);
for(int i = 0; i < N; i++) {
scanf("%d", &H1);
if(i == 0) H0 = H1;
if(H0 > H1) {printf("No"); return 0;}
if(H0 < H1) H1--;
H0 = H1;
}
printf("Yes");
}
``` |
#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
cin>>n;bool flag=true;int h,mem=0;
for(int i=0;i<n;i++){
cin>>h;
if(mem-1<=h)mem=((mem-1==h)?mem:h);
else {flag=false;break;}
}
cout<<(flag?"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 n;
int main(){
cin>>n;bool flag=true;int h,mem=0;
for(int i=0;i<n;i++){
cin>>h;
if(mem-1<=h)mem=((mem-1==h)?mem:h);
else {flag=false;break;}
}
cout<<(flag?"Yes":"No")<<endl;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int h[100005];
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
cin>>h[i];
int max=h[1];
for(int i=2;i<=n;i++)
{
if(h[i-1]-h[i]>1||max-h[i]>1)
{
cout<<"No";
return 0;
}
if(h[i]>max) max=h[i];
}
cout<<"Yes";
return 0;
} | ### 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 h[100005];
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
cin>>h[i];
int max=h[1];
for(int i=2;i<=n;i++)
{
if(h[i-1]-h[i]>1||max-h[i]>1)
{
cout<<"No";
return 0;
}
if(h[i]>max) max=h[i];
}
cout<<"Yes";
return 0;
}
``` |
#include <algorithm>
#include <cstdio>
int main(int argc, const char *argv[]) {
int N, Hi, m;
scanf("%d", &N);
m = 0;
for (int i = 0; i < N; i++) {
scanf("%d", &Hi);
if (!(m <= Hi)) {
printf("No\n");
return 0;
}
m = std::max(m, Hi - 1);
}
printf("Yes\n");
} | ### 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 <algorithm>
#include <cstdio>
int main(int argc, const char *argv[]) {
int N, Hi, m;
scanf("%d", &N);
m = 0;
for (int i = 0; i < N; i++) {
scanf("%d", &Hi);
if (!(m <= Hi)) {
printf("No\n");
return 0;
}
m = std::max(m, Hi - 1);
}
printf("Yes\n");
}
``` |
#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
cin>>n;
int x;
cin>>x;
for (int i=1;i<n;i++)
{
int y=x;
cin>>x;
if(x<y)
{
puts("No");
exit(0);
}
else if (x>y)
{
x--;
}
}
puts("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 n;
int main()
{
cin>>n;
int x;
cin>>x;
for (int i=1;i<n;i++)
{
int y=x;
cin>>x;
if(x<y)
{
puts("No");
exit(0);
}
else if (x>y)
{
x--;
}
}
puts("Yes");
return 0;
}
``` |
#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 = 1; i < n; i++){
if(h[i-1] < h[i]) h[i]--;
}
for(int i = 1; i < n; i++){
if(h[i-1] > h[i]){
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << 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 <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 = 1; i < n; i++){
if(h[i-1] < h[i]) h[i]--;
}
for(int i = 1; i < n; i++){
if(h[i-1] > h[i]){
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
}
``` |
#include <stdio.h>
int main(){
int n,m,pre=1;
scanf("%d", &n);
while(n--){
scanf("%d", &m);
if(m < pre){
printf("No\n");
return 0;
}
if(m>pre) --m;
pre = m;
}
printf("Yes\n");
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 <stdio.h>
int main(){
int n,m,pre=1;
scanf("%d", &n);
while(n--){
scanf("%d", &m);
if(m < pre){
printf("No\n");
return 0;
}
if(m>pre) --m;
pre = m;
}
printf("Yes\n");
return 0;
}
``` |
#include <iostream>
#include <cstdio>
using namespace std;
int n, a[100005];
int main() {
int i, d;
cin>>n;
for(i=1; i<=n; i++) scanf("%d", &a[i]);
for(i=n-1; i>=1; i--) {
d = a[i] - a[i+1];
if(d>1) {cout<<"No"; return 0;}
else if(d==1) a[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 <iostream>
#include <cstdio>
using namespace std;
int n, a[100005];
int main() {
int i, d;
cin>>n;
for(i=1; i<=n; i++) scanf("%d", &a[i]);
for(i=n-1; i>=1; i--) {
d = a[i] - a[i+1];
if(d>1) {cout<<"No"; return 0;}
else if(d==1) a[i]--;
}
cout<<"Yes";
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
long long a[100011];
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
int t=0;
for(int i=1;i<=n;i++){
if(a[i-1]>a[i]){
puts("No");
return 0;
}
if(a[i]-1>=a[i-1]){
a[i]-=1;
}
}
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;
long long a[100011];
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
int t=0;
for(int i=1;i<=n;i++){
if(a[i-1]>a[i]){
puts("No");
return 0;
}
if(a[i]-1>=a[i-1]){
a[i]-=1;
}
}
puts("Yes");
return 0;
}
``` |
#include <stdio.h>
int main() {
int n, h, maxi = 0;
bool valid = true;
scanf("%d", &n);
while (n--) {
scanf("%d", &h);
if (maxi - h > 1) {
valid = false;
break;
}
if (h > maxi)
maxi = h;
}
if (valid)
puts("Yes");
else
puts("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 <stdio.h>
int main() {
int n, h, maxi = 0;
bool valid = true;
scanf("%d", &n);
while (n--) {
scanf("%d", &h);
if (maxi - h > 1) {
valid = false;
break;
}
if (h > maxi)
maxi = h;
}
if (valid)
puts("Yes");
else
puts("No");
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int n,A[100001];
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",&A[i]);
A[1]--;
for(int i=2;i<=n;i++){
if(A[i]<A[i-1]){
puts("No");
return 0;
}
if(A[i]>A[i-1])A[i]--;
}
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,A[100001];
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",&A[i]);
A[1]--;
for(int i=2;i<=n;i++){
if(A[i]<A[i-1]){
puts("No");
return 0;
}
if(A[i]>A[i-1])A[i]--;
}
puts("Yes");
}
``` |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
int m=0,h,i;
for(i=0;i<n;i++){
cin >> h;
if(h<=m-2){
cout << "No" << endl;
return 0;
}
m=max(m,h);
}
cout << "Yes" << 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 main(){
int n;
cin >> n;
int m=0,h,i;
for(i=0;i<n;i++){
cin >> h;
if(h<=m-2){
cout << "No" << endl;
return 0;
}
m=max(m,h);
}
cout << "Yes" << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,a,b,i,f=0;
cin>>n>>a;
for(i=0;i<n-1;i++){
cin>>b;
if(a<b) f=0;
else if(a-1==b && !f) f=1;
else if(a!=b){
cout<<"No";
return 0;
}
a=b;
}
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 <bits/stdc++.h>
using namespace std;
int main(){
int n,a,b,i,f=0;
cin>>n>>a;
for(i=0;i<n-1;i++){
cin>>b;
if(a<b) f=0;
else if(a-1==b && !f) f=1;
else if(a!=b){
cout<<"No";
return 0;
}
a=b;
}
cout<<"Yes";
}
``` |
#include <iostream>
using namespace std;
int main() {
int N;
cin >> N;
bool ans = true;
int before = 0;
for (int i = 0; i < N; i++) {
int H;
cin >> H;
if (before-1 > H) ans = false;
before = H + (before-1==H ? 1 : 0);
}
cout << (ans ? "Yes" : "No") << 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 <iostream>
using namespace std;
int main() {
int N;
cin >> N;
bool ans = true;
int before = 0;
for (int i = 0; i < N; i++) {
int H;
cin >> H;
if (before-1 > H) ans = false;
before = H + (before-1==H ? 1 : 0);
}
cout << (ans ? "Yes" : "No") << endl;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int a[100005];
int main()
{
int n;
int max=0;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
if(a[i]>max)
{
max=a[i];
}
else
{
if(max-a[i]>=2)
{
cout<<"No";
return 0;
}
}
}
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 a[100005];
int main()
{
int n;
int max=0;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
if(a[i]>max)
{
max=a[i];
}
else
{
if(max-a[i]>=2)
{
cout<<"No";
return 0;
}
}
}
cout<<"Yes";
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int n,A[100010];
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",&A[i]),A[i]--;
for(int i=1;i<=n;i++){
if(A[i]<A[i-1]){
A[i]++;
if(A[i]<A[i-1]){
puts("No");
return 0;
}
}
}
puts("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 n,A[100010];
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",&A[i]),A[i]--;
for(int i=1;i<=n;i++){
if(A[i]<A[i-1]){
A[i]++;
if(A[i]<A[i-1]){
puts("No");
return 0;
}
}
}
puts("Yes");
return 0;
}
``` |
#include<iostream>
using namespace std;
#define ll long long int
int main(){
ll i,j,k,n,m,t;
ll pre=0;
cin>>n;
ll f=1;
while(n--){
cin>>k;
if(k<pre) {
f=0;
}
if(k-1>=pre) pre=k-1;
else pre=k;
}
if(f) cout<<"Yes\n";
else cout<<"No\n";
} | ### 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<iostream>
using namespace std;
#define ll long long int
int main(){
ll i,j,k,n,m,t;
ll pre=0;
cin>>n;
ll f=1;
while(n--){
cin>>k;
if(k<pre) {
f=0;
}
if(k-1>=pre) pre=k-1;
else pre=k;
}
if(f) cout<<"Yes\n";
else cout<<"No\n";
}
``` |
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100010
int n,a[MAXN];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;++i)
{
scanf("%d",a+i);
}
for(int i=1;i<=n;++i)
{
if(a[i-1]<a[i])--a[i];
if(a[i-1]>a[i])return puts("No"),0;
}
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;
#define MAXN 100010
int n,a[MAXN];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;++i)
{
scanf("%d",a+i);
}
for(int i=1;i<=n;++i)
{
if(a[i-1]<a[i])--a[i];
if(a[i-1]>a[i])return puts("No"),0;
}
puts("Yes");
}
``` |
/*
ID: wangjun30
TASK:
LANG: C++
*/
#include<iostream>
using namespace std;
int main(){
int n,cur;
cin>>n>>cur;
for(int i=1;i<n;i++){
int x;
cin>>x;
if(x<cur-1){
cout<<"No";
return 0;
}
cur=max(x,cur);
}
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
/*
ID: wangjun30
TASK:
LANG: C++
*/
#include<iostream>
using namespace std;
int main(){
int n,cur;
cin>>n>>cur;
for(int i=1;i<n;i++){
int x;
cin>>x;
if(x<cur-1){
cout<<"No";
return 0;
}
cur=max(x,cur);
}
cout<<"Yes";
return 0;
}
``` |
#include<cstdio>
const int N=1e5+10;
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])a[i-1]--;
for(int i=2;i<=n;i++)
if(a[i]<a[i-1])
{
puts("No");
return 0;
}
puts("Yes");
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<cstdio>
const int N=1e5+10;
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])a[i-1]--;
for(int i=2;i<=n;i++)
if(a[i]<a[i-1])
{
puts("No");
return 0;
}
puts("Yes");
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main(){
int a;
cin>>a;
int now;
cin>>now;
now--;
for(int i=0;i<a-1;i++){
int num;
cin>>num;
if(num<now){
cout<<"No"<<endl;
return 0;
}
else now=max(now,num-1);
}
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 a;
cin>>a;
int now;
cin>>now;
now--;
for(int i=0;i<a-1;i++){
int num;
cin>>num;
if(num<now){
cout<<"No"<<endl;
return 0;
}
else now=max(now,num-1);
}
cout<<"Yes"<<endl;
return 0;
}
``` |
#include <iostream>
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;
}
| ### 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;
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;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k=-1;
cin >> n;
int a[n];
for(int i=0;i<n;i++)cin >> a[i];
for(int i=0;i<n;i++){
if(a[i]+1<k){
cout << "No" << endl;
return 0;
}
k=max(k,a[i]);
}
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,k=-1;
cin >> n;
int a[n];
for(int i=0;i<n;i++)cin >> a[i];
for(int i=0;i<n;i++){
if(a[i]+1<k){
cout << "No" << endl;
return 0;
}
k=max(k,a[i]);
}
cout << "Yes" << endl;
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int a[100005],b[100005];
for(int i=0;i<n;i++)
cin>>a[i],b[i]=a[i];
sort(a,a+n);
for(int i=0;i<n;i++)
{
if(b[i]-a[i]>1)
{
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[100005],b[100005];
for(int i=0;i<n;i++)
cin>>a[i],b[i]=a[i];
sort(a,a+n);
for(int i=0;i<n;i++)
{
if(b[i]-a[i]>1)
{
cout<<"No";
return 0;
}
}
cout<<"Yes";
return 0;
}
``` |
#include<iostream>
using namespace std;
int main() {
int N,H;
cin >> N;
int max=0;
for (int i=0;i<N;i++) {
cin >> H;
if (H>max) max=H;
else if (H<max-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 main() {
int N,H;
cin >> N;
int max=0;
for (int i=0;i<N;i++) {
cin >> H;
if (H>max) max=H;
else if (H<max-1) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
}
``` |
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
const int mx = 100005;
int n, h[mx];
int main(){
scanf("%d%d", &n, h);
rep(i,n-1){
scanf("%d", h+i+1);
if(h[i]-1 == h[i+1]) h[i+1]++;
else if(h[i] > h[i+1]) return 0*puts("No");
}
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;
#define rep(i,n) for(int i = 0; i < n; i++)
const int mx = 100005;
int n, h[mx];
int main(){
scanf("%d%d", &n, h);
rep(i,n-1){
scanf("%d", h+i+1);
if(h[i]-1 == h[i+1]) h[i+1]++;
else if(h[i] > h[i+1]) return 0*puts("No");
}
puts("Yes");
}
``` |
#include<bits/stdc++.h>
using namespace std;
int n,a[100005];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=n;i++)
{
if(a[i]<a[i-1])
{
printf("No");
return 0;
}
if(a[i]>a[i-1])
a[i]--;
}
printf("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 n,a[100005];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=n;i++)
{
if(a[i]<a[i-1])
{
printf("No");
return 0;
}
if(a[i]>a[i-1])
a[i]--;
}
printf("Yes");
}
``` |
#include<bits/stdc++.h>
using namespace std;
int a[100005];
int main(){
int n,flag=0;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
if(a[i-1]>a[i]){cout<<"No";return 0;}
if(a[i-1]!=a[i])a[i]--;
}
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;
int a[100005];
int main(){
int n,flag=0;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
if(a[i-1]>a[i]){cout<<"No";return 0;}
if(a[i-1]!=a[i])a[i]--;
}
cout<<"Yes";
}
``` |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll n,i;scanf("%lld",&n);
ll a[n];
for(i=0;i<n;i++) scanf("%lld",&a[i]);
for(i=1;i<n;i++){
if(a[i-1]>a[i]){
printf("No\n");return 0;
} else if(a[i-1]<a[i]) a[i]--;
}
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<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll n,i;scanf("%lld",&n);
ll a[n];
for(i=0;i<n;i++) scanf("%lld",&a[i]);
for(i=1;i<n;i++){
if(a[i-1]>a[i]){
printf("No\n");return 0;
} else if(a[i-1]<a[i]) a[i]--;
}
printf("Yes\n");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-2;i>=0;i--){
if(a[i+1]+1<a[i]){
cout << "No";
return 0;
}
if(a[i+1]+1==a[i])a[i]--;
}
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 main(){
int n;
cin >> n;
int a[n];
for(int i=0;i<n;i++)cin >> a[i];
for(int i=n-2;i>=0;i--){
if(a[i+1]+1<a[i]){
cout << "No";
return 0;
}
if(a[i+1]+1==a[i])a[i]--;
}
cout << "Yes";
}
``` |
#include<cstdio>
#define maxn 100005
using namespace std;
int n,a[maxn];
int main(){
scanf("%d",&n);
for (int i=1;i<=n;i++) scanf("%d",&a[i]),a[i]--;
for (int i=2;i<=n;i++){
if (a[i]<a[i-1]){
a[i]++;
if (a[i]<a[i-1]){printf("No\n");return 0;}
}
}
printf("Yes\n");
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>
#define maxn 100005
using namespace std;
int n,a[maxn];
int main(){
scanf("%d",&n);
for (int i=1;i<=n;i++) scanf("%d",&a[i]),a[i]--;
for (int i=2;i<=n;i++){
if (a[i]<a[i-1]){
a[i]++;
if (a[i]<a[i-1]){printf("No\n");return 0;}
}
}
printf("Yes\n");
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int n,h[100010];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&h[i]);
for(int i=n;i>1;i--)
if(h[i-1]-h[i]>=2)
{
printf("No\n");
return 0;
}
else if(h[i-1]-h[i]==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<bits/stdc++.h>
using namespace std;
int n,h[100010];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&h[i]);
for(int i=n;i>1;i--)
if(h[i-1]-h[i]>=2)
{
printf("No\n");
return 0;
}
else if(h[i-1]-h[i]==1)
h[i-1]--;
printf("Yes\n");
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int a,n,cant,fo;
int main() {
scanf("%d",&n);
for(int i=1; i<=n; i++) {
scanf("%d",&a);
if(a<fo)cant=1;
else if(a!=fo)fo=max(a-1,fo);
}
if(cant)printf("No");
else printf("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;
int a,n,cant,fo;
int main() {
scanf("%d",&n);
for(int i=1; i<=n; i++) {
scanf("%d",&a);
if(a<fo)cant=1;
else if(a!=fo)fo=max(a-1,fo);
}
if(cant)printf("No");
else printf("Yes");
return 0;
}
``` |
#include <iostream>
#include <cstdio>
using namespace std;
int n, a[100005];
int main() {
int i;
cin>>n;
for(i=1; i<=n; i++) scanf("%d", &a[i]);
for(i=n-1; i>=1; i--) {
if(a[i] > a[i+1]) {
a[i]--;
if(a[i] > a[i+1]) {cout<<"No"; return 0;}
}
}
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 <cstdio>
using namespace std;
int n, a[100005];
int main() {
int i;
cin>>n;
for(i=1; i<=n; i++) scanf("%d", &a[i]);
for(i=n-1; i>=1; i--) {
if(a[i] > a[i+1]) {
a[i]--;
if(a[i] > a[i+1]) {cout<<"No"; return 0;}
}
}
cout<<"Yes";
return 0;
}
``` |
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e5+5;
int n,a[N],minn[N];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;++i) scanf("%d",&a[i]);
for(int i=1;i<=n;++i)
{
if(a[i]>a[i-1]) --a[i];
if(a[i]<a[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<cstdio>
#include<algorithm>
using namespace std;
const int N=1e5+5;
int n,a[N],minn[N];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;++i) scanf("%d",&a[i]);
for(int i=1;i<=n;++i)
{
if(a[i]>a[i-1]) --a[i];
if(a[i]<a[i-1]) {puts("No");return 0;}
}
puts("Yes");
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,aa[500000];
cin>>n;
for(int i=0;i<n;i++)cin>>aa[i];
int mx=0;
for(int i=0;i<n;i++){
if(mx>aa[i]){
if(mx-aa[i]>1){
cout<<"No";
return 0;
}
}else mx=aa[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;
int main() {
int n,aa[500000];
cin>>n;
for(int i=0;i<n;i++)cin>>aa[i];
int mx=0;
for(int i=0;i<n;i++){
if(mx>aa[i]){
if(mx-aa[i]>1){
cout<<"No";
return 0;
}
}else mx=aa[i];
}
cout<<"Yes";
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
int a,b; cin>>a;
bool flg=true;
--a;
for(int i=0; i<n-1; ++i){
cin>>b;
if(a<b)a=b-1;
else if(a==b)a=b;
else{flg=false; break;}
}
if(flg)cout<<"Yes"<<endl;
else cout<<"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 <bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
int a,b; cin>>a;
bool flg=true;
--a;
for(int i=0; i<n-1; ++i){
cin>>b;
if(a<b)a=b-1;
else if(a==b)a=b;
else{flg=false; break;}
}
if(flg)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int m = 0;
for (int i = 0; i < n; i++) {
int a;
scanf("%d", &a);
if (a < m) {
cout << "No" << endl;
return 0;
}
m = max(m, a - 1);
}
cout << "Yes" << endl;
return 0;
}
| ### 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 m = 0;
for (int i = 0; i < n; i++) {
int a;
scanf("%d", &a);
if (a < m) {
cout << "No" << endl;
return 0;
}
m = max(m, a - 1);
}
cout << "Yes" << endl;
return 0;
}
``` |
#include <cstdio>
using namespace std;
int a[100005];
int main(void)
{
int n,i,h;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
for(i=1,h=a[0];i<n;i++){
if(h-a[i]>=2){
printf("No");
return 0;
}
if(a[i]>h) h=a[i];
}
printf("Yes");
return 0;
} | ### 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 <cstdio>
using namespace std;
int a[100005];
int main(void)
{
int n,i,h;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
for(i=1,h=a[0];i<n;i++){
if(h-a[i]>=2){
printf("No");
return 0;
}
if(a[i]>h) h=a[i];
}
printf("Yes");
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int h[n+10];
for(int i=0;i<n;i++)
cin>>h[i];
for(int i=n-1;i>0;i--)
if(h[i]<h[i-1])h[i-1]--;
for(int i=0;i<n-1;i++)
if(h[i]>h[i+1]){
cout<<"No";
return 0;
}
cout<<"Yes";
return 0;
} | ### 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 h[n+10];
for(int i=0;i<n;i++)
cin>>h[i];
for(int i=n-1;i>0;i--)
if(h[i]<h[i-1])h[i-1]--;
for(int i=0;i<n-1;i++)
if(h[i]>h[i+1]){
cout<<"No";
return 0;
}
cout<<"Yes";
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int m=0;
bool f=1;
for(int i=0;i<n;i++){
int h;
cin>>h;
if(m-h<2)
m=max(m,h);
else
f=0;
}
cout<<(f?"Yes":"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 main(){
int n;
cin>>n;
int m=0;
bool f=1;
for(int i=0;i<n;i++){
int h;
cin>>h;
if(m-h<2)
m=max(m,h);
else
f=0;
}
cout<<(f?"Yes":"No")<<endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n,a[100005];
bool flag;
signed main(){
scanf("%d",&n);
for(int i=1;i<=n;++i){
scanf("%d",&a[i]);
if(a[i]-a[i-1]>0) a[i]--;
if(a[i]<a[i-1]){
puts("No");
return 0;
}
}
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,a[100005];
bool flag;
signed main(){
scanf("%d",&n);
for(int i=1;i<=n;++i){
scanf("%d",&a[i]);
if(a[i]-a[i-1]>0) a[i]--;
if(a[i]<a[i-1]){
puts("No");
return 0;
}
}
puts("Yes");
}
``` |
#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];
}
if(h[i]<mxh-1){
ans = "No";
}
}
cout << ans << 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);
int mxh = 0;
string ans = "Yes";
for(int i=0; i<n; i++){
cin >> h[i];
if(h[i]>mxh){
mxh = h[i];
}
if(h[i]<mxh-1){
ans = "No";
}
}
cout << ans << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main(){
int N,i;cin>>N;int H[N];
for(i=0;i<N;i++)cin>>H[i];
for(i=N-1;i>0;i--){
if(H[i-1]>H[i]){
if(H[i-1]-H[i]==1)H[i-1]--;
else break;
}
}
if(i==0)cout<<"Yes"<<endl;
else cout<<"No"<<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 main(){
int N,i;cin>>N;int H[N];
for(i=0;i<N;i++)cin>>H[i];
for(i=N-1;i>0;i--){
if(H[i-1]>H[i]){
if(H[i-1]-H[i]==1)H[i-1]--;
else break;
}
}
if(i==0)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int maks=0, a;
for(int i=0; i<n; i++)
{
cin>>a;
maks=max(maks,a);
if(a<maks-1)
{
cout<<"No";
return 0;
}
}
cout<<"Yes";
return 0;
}
| ### 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 maks=0, a;
for(int i=0; i<n; i++)
{
cin>>a;
maks=max(maks,a);
if(a<maks-1)
{
cout<<"No";
return 0;
}
}
cout<<"Yes";
return 0;
}
``` |
#include <iostream>
using namespace std;
int main(){
int n,flag=1;;
cin>>n;
int a[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]) flag=0;
if(a[i]>a[i-1]) a[i]--;
}
if(flag) cout<<"Yes\n";
else cout<<"No\n";
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;
int main(){
int n,flag=1;;
cin>>n;
int a[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]) flag=0;
if(a[i]>a[i-1]) a[i]--;
}
if(flag) cout<<"Yes\n";
else cout<<"No\n";
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
int a[n];
cin >> a[0];
int r=a[0];
for(int i=1;i<n;i++){
cin >> a[i];
if(r>=a[i]+2){cout << "No" << endl;
return 0;}
if(r<a[i]){r=a[i];}
}
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 a[n];
cin >> a[0];
int r=a[0];
for(int i=1;i<n;i++){
cin >> a[i];
if(r>=a[i]+2){cout << "No" << endl;
return 0;}
if(r<a[i]){r=a[i];}
}
cout << "Yes" << endl;
}
``` |
#include<iostream>
using namespace std;
int n;
int h[100005],mn;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
cin>>h[i];
mn=h[n];
for(int i=n-1;i>=1;i--)
{
if(mn>h[i]) mn=h[i];
if(h[i]-2>=mn)
{
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 n;
int h[100005],mn;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
cin>>h[i];
mn=h[n];
for(int i=n-1;i>=1;i--)
{
if(mn>h[i]) mn=h[i];
if(h[i]-2>=mn)
{
cout<<"No";
return 0;
}
}
cout<<"Yes";
}
``` |
#include<iostream>
using namespace std;
int N,H[1<<17];
int main()
{
cin>>N;
for(int i=0;i<N;i++)cin>>H[i];
for(int i=N-1;i--;)
{
if(H[i]>H[i+1])H[i]--;
if(H[i]>H[i+1])
{
cout<<"No"<<endl;
return 0;
}
}
cout<<"Yes"<<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<iostream>
using namespace std;
int N,H[1<<17];
int main()
{
cin>>N;
for(int i=0;i<N;i++)cin>>H[i];
for(int i=N-1;i--;)
{
if(H[i]>H[i+1])H[i]--;
if(H[i]>H[i+1])
{
cout<<"No"<<endl;
return 0;
}
}
cout<<"Yes"<<endl;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int h[100006];
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;++i) scanf("%d",&h[i]);
for(int i=n;i>=2;--i) {
if(h[i]+1==h[i-1]) h[i-1]--;
else if(h[i]+1<h[i-1]) {
printf("No");
return 0;
}
}
printf("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 h[100006];
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;++i) scanf("%d",&h[i]);
for(int i=n;i>=2;--i) {
if(h[i]+1==h[i-1]) h[i-1]--;
else if(h[i]+1<h[i-1]) {
printf("No");
return 0;
}
}
printf("Yes");
return 0;
}
``` |
#include <cstdio>
int n;
int h[100010];
int main() {
int i;
scanf("%d", &n);
for(i=1; i<=n; i++) scanf("%d", &h[i]);
for(i=1; i<=n; i++) {
if(h[i-1]>h[i]) {
printf("No\n");
return 0;
}
else if(h[i-1]<h[i]) h[i]--;
}
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 <cstdio>
int n;
int h[100010];
int main() {
int i;
scanf("%d", &n);
for(i=1; i<=n; i++) scanf("%d", &h[i]);
for(i=1; i<=n; i++) {
if(h[i-1]>h[i]) {
printf("No\n");
return 0;
}
else if(h[i-1]<h[i]) h[i]--;
}
printf("Yes\n");
return 0;
}
``` |
# include <bits/stdc++.h>
# define ll long long
# define pb push_back
# define mk make_pair
# define fr first
# define sc second
using namespace std;
int n,ans,x,y;
int main(){
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>x;
if(x>y)x--;
if(x<y){cout<<"No";return 0;}
y=x;
}
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>
# define ll long long
# define pb push_back
# define mk make_pair
# define fr first
# define sc second
using namespace std;
int n,ans,x,y;
int main(){
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>x;
if(x>y)x--;
if(x<y){cout<<"No";return 0;}
y=x;
}
cout<<"Yes";
}
``` |
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int n,H[100010];
cin >> n;
for(int i=0;i<n;i++){
cin >> H[i];
}
for(int i=1;i<n;i++){
if(H[i]-1 >= H[i-1]){
H[i]--;
}
}
cout << (is_sorted(H,H+n) ? "Yes" : "No") << "\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 <iostream>
#include <algorithm>
using namespace std;
int main() {
int n,H[100010];
cin >> n;
for(int i=0;i<n;i++){
cin >> H[i];
}
for(int i=1;i<n;i++){
if(H[i]-1 >= H[i-1]){
H[i]--;
}
}
cout << (is_sorted(H,H+n) ? "Yes" : "No") << "\n";
return 0;
}
``` |
#include <cstdio>
#include <algorithm>
using namespace std;
int N,mx;
int main() {
scanf("%d",&N);
for (int i = 0,H;i < N;i++) {
scanf("%d",&H);
if (mx-1 > H) return printf("No\n"),0;
mx = max(mx,H);
}
printf("Yes\n");
}
| ### 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 <cstdio>
#include <algorithm>
using namespace std;
int N,mx;
int main() {
scanf("%d",&N);
for (int i = 0,H;i < N;i++) {
scanf("%d",&H);
if (mx-1 > H) return printf("No\n"),0;
mx = max(mx,H);
}
printf("Yes\n");
}
``` |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int m,h;
cin>>m;
for(int i=1;i<n;i++){
cin>>h;
m=max(m,h);
if(m-1>h){
puts("No");
return 0;
}
}
puts("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<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int m,h;
cin>>m;
for(int i=1;i<n;i++){
cin>>h;
m=max(m,h);
if(m-1>h){
puts("No");
return 0;
}
}
puts("Yes");
return 0;
}
``` |
#include <iostream>
using namespace std;
int main(){
int n,b=-2;
cin>>n;
while(n--){
int e;
cin>>e;
if(e<b){
cout<<"No"<<endl;
return 0;
}
if(e>b){
b=e-1;
}
}
cout<<"Yes"<<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 <iostream>
using namespace std;
int main(){
int n,b=-2;
cin>>n;
while(n--){
int e;
cin>>e;
if(e<b){
cout<<"No"<<endl;
return 0;
}
if(e>b){
b=e-1;
}
}
cout<<"Yes"<<endl;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int n,a[100010],minn=0X7FFFFFFF;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=n;i>=1;i--){
if(a[i]-minn>=2){
cout<<"No"<<endl;
return 0;
}
minn=min(minn,a[i]);
}
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 n,a[100010],minn=0X7FFFFFFF;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=n;i>=1;i--){
if(a[i]-minn>=2){
cout<<"No"<<endl;
return 0;
}
minn=min(minn,a[i]);
}
cout<<"Yes"<<endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
long n,i,cur;
cin >> n;
vector<long> h(n);
for(i=0; i<n; i++){
cin >> h[i];
}
for(i=n-1; i>0; i--){
if(h[i]-h[i-1]==-1){
h[i-1]--;
}else if(h[i]<h[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 <bits/stdc++.h>
using namespace std;
int main() {
long n,i,cur;
cin >> n;
vector<long> h(n);
for(i=0; i<n; i++){
cin >> h[i];
}
for(i=n-1; i>0; i--){
if(h[i]-h[i-1]==-1){
h[i-1]--;
}else if(h[i]<h[i-1]){
cout << "No"; return 0;
}
}
cout << "Yes";
return 0;
}
``` |
#include <stdio.h>
int main(void){
int n;
scanf("%d", &n);
int h[n];
for(int i=0;i<n;i++){
scanf("%d", &h[i]);
}
for(int i=n-2;i>=0;i--){
if(h[i]>h[i+1]+1){
printf("No");
return 0;
}else if(h[i]==h[i+1]+1){
h[i]--;
}
}
printf("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 <stdio.h>
int main(void){
int n;
scanf("%d", &n);
int h[n];
for(int i=0;i<n;i++){
scanf("%d", &h[i]);
}
for(int i=n-2;i>=0;i--){
if(h[i]>h[i+1]+1){
printf("No");
return 0;
}else if(h[i]==h[i+1]+1){
h[i]--;
}
}
printf("Yes");
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int n,a[100050],mi;
bool ans=1;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(int i=n-1;i>=1;i--)
{
if(a[i]-a[i+1]>1)ans=0;
if(a[i]-a[i+1]==1)a[i]--;
}
puts(ans?"Yes":"No");
} | ### 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[100050],mi;
bool ans=1;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(int i=n-1;i>=1;i--)
{
if(a[i]-a[i+1]>1)ans=0;
if(a[i]-a[i+1]==1)a[i]--;
}
puts(ans?"Yes":"No");
}
``` |
#include<bits/stdc++.h>
using namespace std;
int a[100001];
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]-1>=a[i-1])a[i]--;
if(a[i-1]>a[i]){
printf("No");
return 0;
}
}
printf("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 a[100001];
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]-1>=a[i-1])a[i]--;
if(a[i-1]>a[i]){
printf("No");
return 0;
}
}
printf("Yes");
}
``` |
#include <cstdio>
int main() {
int N;
std::scanf("%d", &N);
int b, n, flag = 0;
std::scanf("%d", &b);
for (int i = 1; i < N; i++) {
std::scanf("%d", &n);
if (b < n) {
n--;
}
if (n < b) {
std::printf("No\n");
return 0;
}
b = n;
}
std::printf("Yes\n");
return 0;
} | ### 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 <cstdio>
int main() {
int N;
std::scanf("%d", &N);
int b, n, flag = 0;
std::scanf("%d", &b);
for (int i = 1; i < N; i++) {
std::scanf("%d", &n);
if (b < n) {
n--;
}
if (n < b) {
std::printf("No\n");
return 0;
}
b = n;
}
std::printf("Yes\n");
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int A[100001];
int main(){
int a,i;
cin>>a,scanf("%d",&A[1]),A[1]--;
for(i=2;i<=a;i++){
scanf("%d",&A[i]);
if(A[i]>A[i-1])A[i]--;
if(A[i]<A[i-1]){
puts("No");
return 0;
}
}
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 A[100001];
int main(){
int a,i;
cin>>a,scanf("%d",&A[1]),A[1]--;
for(i=2;i<=a;i++){
scanf("%d",&A[i]);
if(A[i]>A[i-1])A[i]--;
if(A[i]<A[i-1]){
puts("No");
return 0;
}
}
puts("Yes");
}
``` |
#include<bits/stdc++.h>
using namespace std;
int n, ok, a[100005];
int main(){
cin>>n;
for(int i=1;i<=n;i++){
scanf("%d", &a[i]);
}
for(int i=1;i<=n;i++){
if(a[i]-1>=a[i-1]) a[i]--;
if(i!=n&&a[i]>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;
int n, ok, a[100005];
int main(){
cin>>n;
for(int i=1;i<=n;i++){
scanf("%d", &a[i]);
}
for(int i=1;i<=n;i++){
if(a[i]-1>=a[i-1]) a[i]--;
if(i!=n&&a[i]>a[i+1]) {
cout<<"No";
return 0;
}
}
cout<<"Yes";
}
``` |
#include<bits/stdc++.h>
using namespace std;
int n, a[100010]={0};
int main() {
cin >> n;
int f = 0;
for(int i = 1; i <= n; i++) {
scanf("%d", a + i);
if(a[i] < a[i-1]) a[i]++;
if(a[i] < a[i-1]) f = 1;
}
if(f) cout << "No";
else 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 n, a[100010]={0};
int main() {
cin >> n;
int f = 0;
for(int i = 1; i <= n; i++) {
scanf("%d", a + i);
if(a[i] < a[i-1]) a[i]++;
if(a[i] < a[i-1]) f = 1;
}
if(f) cout << "No";
else cout << "Yes";
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,ima=0,i,dan,kotae=1;
cin>>n;
for(i=0;i<n;i++){
cin>>dan;
if(ima<dan){
ima=dan-1;
}else if(ima>dan){
kotae=0;
break;
}
}
if(kotae){
cout<<"Yes";
}else{
cout<<"No";
}
} | ### 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,ima=0,i,dan,kotae=1;
cin>>n;
for(i=0;i<n;i++){
cin>>dan;
if(ima<dan){
ima=dan-1;
}else if(ima>dan){
kotae=0;
break;
}
}
if(kotae){
cout<<"Yes";
}else{
cout<<"No";
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,h,maxh=0; cin>>n;
for(int i=0;i<n;i++){
cin>>h;
if(maxh>h){cout<<"No"; return 0;}
maxh=max(maxh,h-1);
}
cout<<"Yes";
} | ### 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,h,maxh=0; cin>>n;
for(int i=0;i<n;i++){
cin>>h;
if(maxh>h){cout<<"No"; return 0;}
maxh=max(maxh,h-1);
}
cout<<"Yes";
}
``` |
#include<cstdio>
#include<algorithm>
int main(){
int n,b[100],a[100];
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&b[i]);
if(b[i]>=i+2){
printf("-1");
return 0;
}
}
//b[i]==iなる最も大きいiを選んで取り除く
//という操作で選んだ数列のreverse
for(int ia=n-1;ia>=0;ia--){
int ib=ia;
while(b[ib]<ib+1)ib--;
a[ia]=b[ib];
while(ib<ia){
b[ib]=b[ib+1];
ib++;
}
}
for(int i=0;i<n;i++)printf("%d\n",a[i]);
return 0;
} | ### Prompt
Your task is to create a CPP solution to the following problem:
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1
### Response
```cpp
#include<cstdio>
#include<algorithm>
int main(){
int n,b[100],a[100];
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&b[i]);
if(b[i]>=i+2){
printf("-1");
return 0;
}
}
//b[i]==iなる最も大きいiを選んで取り除く
//という操作で選んだ数列のreverse
for(int ia=n-1;ia>=0;ia--){
int ib=ia;
while(b[ib]<ib+1)ib--;
a[ia]=b[ib];
while(ib<ia){
b[ib]=b[ib+1];
ib++;
}
}
for(int i=0;i<n;i++)printf("%d\n",a[i]);
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin>>n;
vector<int> v(n+1);
v[0]=-1;
vector<int> ans;
for(int i=1;i<=n;i++)
cin>>v[i];
for(int i=n;i>=1;i--){
int j;
for(j=i;j>=1;j--){
if(j==v[j]){
ans.emplace_back(j);
v.erase(v.begin()+j);
break;
}
}
if(j==0){
cout<<-1<<endl;
return 0;
}
}
reverse(ans.begin(),ans.end());
for(int it:ans)
cout<<it<<endl;
}
| ### Prompt
Please provide a cpp coded solution to the problem described below:
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin>>n;
vector<int> v(n+1);
v[0]=-1;
vector<int> ans;
for(int i=1;i<=n;i++)
cin>>v[i];
for(int i=n;i>=1;i--){
int j;
for(j=i;j>=1;j--){
if(j==v[j]){
ans.emplace_back(j);
v.erase(v.begin()+j);
break;
}
}
if(j==0){
cout<<-1<<endl;
return 0;
}
}
reverse(ans.begin(),ans.end());
for(int it:ans)
cout<<it<<endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
int n;
cin >> n;
vector<int> b;
for(int i = 0; i < n; i++){
int bb;
cin >> bb;
b.push_back(bb);
}
vector<int> ans;
for(int i = (int)b.size()-1; i >= 0; i--){
if(i+1-b[i] == 0){
ans.push_back(b[i]);
b.erase(b.begin()+i);
i = (int)b.size();
}
}
if((int)b.size() == 0){
for(int i = n-1; i >= 0; i--)cout << ans[i] << endl;
}
else cout << -1 << endl;
return 0;
} | ### Prompt
Please formulate a cpp solution to the following problem:
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
int n;
cin >> n;
vector<int> b;
for(int i = 0; i < n; i++){
int bb;
cin >> bb;
b.push_back(bb);
}
vector<int> ans;
for(int i = (int)b.size()-1; i >= 0; i--){
if(i+1-b[i] == 0){
ans.push_back(b[i]);
b.erase(b.begin()+i);
i = (int)b.size();
}
}
if((int)b.size() == 0){
for(int i = n-1; i >= 0; i--)cout << ans[i] << endl;
}
else cout << -1 << endl;
return 0;
}
``` |
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long
using namespace std;
int main(){
int n;cin>>n;
vector<int> b(n);
rep(i,n)cin>>b[i];
vector<int> result;
rep(i,n){
int c=-1;
rep(j,b.size()){
if(j+1==b[j] && j+1>c)c=j+1;
}
if(c==-1){
cout<<-1<<endl;
return 0;
}
auto it = b.begin();
rep(i,c-1)it++;
b.erase(it);
result.push_back(c);
}
rep(i,n)cout<<result[n-1-i]<<endl;
return 0;
} | ### Prompt
Please provide a Cpp coded solution to the problem described below:
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1
### Response
```cpp
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long
using namespace std;
int main(){
int n;cin>>n;
vector<int> b(n);
rep(i,n)cin>>b[i];
vector<int> result;
rep(i,n){
int c=-1;
rep(j,b.size()){
if(j+1==b[j] && j+1>c)c=j+1;
}
if(c==-1){
cout<<-1<<endl;
return 0;
}
auto it = b.begin();
rep(i,c-1)it++;
b.erase(it);
result.push_back(c);
}
rep(i,n)cout<<result[n-1-i]<<endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
int main() {
ll n;
vector<ll>a;
cin>>n;
for(int i=0;i<n;i++){
ll x;
cin>>x;
a.push_back(x);
}
vector<ll>b;
ll m=n;
for(int i=n-1;i>=0;i--){
if(a[i]==i+1){
b.push_back(a[i]);
a.erase(a.begin()+i);
m--;
i=m;
continue;
}
if(i==0){
cout << -1;
return 0;
}
}
for(int i=n-1;i>=0;i--){
cout << b[i]<<endl;
}
return 0;
} | ### Prompt
Your task is to create a Cpp solution to the following problem:
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
int main() {
ll n;
vector<ll>a;
cin>>n;
for(int i=0;i<n;i++){
ll x;
cin>>x;
a.push_back(x);
}
vector<ll>b;
ll m=n;
for(int i=n-1;i>=0;i--){
if(a[i]==i+1){
b.push_back(a[i]);
a.erase(a.begin()+i);
m--;
i=m;
continue;
}
if(i==0){
cout << -1;
return 0;
}
}
for(int i=n-1;i>=0;i--){
cout << b[i]<<endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int n, b[N], a[N];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", b + i);
vector<int> vec;
for (int i = 1; i <= n; ++i) vec.push_back(i);
for (int i = n; i; --i) {
if ((int)vec.size() < b[i]) return puts("-1"), 0;
a[vec[b[i] - 1]] = b[i];
vec.erase(vec.begin() + b[i] - 1);
}
for (int i = 1; i <= n; ++i) printf("%d\n", a[i]);
return 0;
} | ### Prompt
Generate a Cpp solution to the following problem:
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int n, b[N], a[N];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", b + i);
vector<int> vec;
for (int i = 1; i <= n; ++i) vec.push_back(i);
for (int i = n; i; --i) {
if ((int)vec.size() < b[i]) return puts("-1"), 0;
a[vec[b[i] - 1]] = b[i];
vec.erase(vec.begin() + b[i] - 1);
}
for (int i = 1; i <= n; ++i) printf("%d\n", a[i]);
return 0;
}
``` |
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
if (x > i) {
cout << -1 << endl;
return 0;
}
a.insert(a.begin() + x - 1, x);
}
for (int i = 0; i < n; i++)
cout << a[i] << endl;
return 0;
} | ### Prompt
Generate a CPP solution to the following problem:
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1
### Response
```cpp
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
if (x > i) {
cout << -1 << endl;
return 0;
}
a.insert(a.begin() + x - 1, x);
}
for (int i = 0; i < n; i++)
cout << a[i] << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b)
{
return b ? gcd(b, a % b) : a;
}
void solve()
{
int n;
cin >> n;
vector<int> b(n);
for (auto&& i : b)
{
cin >> i;
}
stack<int> s;
while(n)
{
for(int i = n - 1; i >= 0; i--)
{
if(b[i] == i + 1)
{
b.erase(begin(b) + i);
s.push(i + 1);
break;
}
}
if(b.size() == n--)
{
cout << "-1\n";
return;
}
}
while(s.size())
{
cout << s.top() << "\n";
s.pop();
}
}
int main()
{
solve();
}
| ### Prompt
Please provide a Cpp coded solution to the problem described below:
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b)
{
return b ? gcd(b, a % b) : a;
}
void solve()
{
int n;
cin >> n;
vector<int> b(n);
for (auto&& i : b)
{
cin >> i;
}
stack<int> s;
while(n)
{
for(int i = n - 1; i >= 0; i--)
{
if(b[i] == i + 1)
{
b.erase(begin(b) + i);
s.push(i + 1);
break;
}
}
if(b.size() == n--)
{
cout << "-1\n";
return;
}
}
while(s.size())
{
cout << s.top() << "\n";
s.pop();
}
}
int main()
{
solve();
}
``` |
#include <bits/stdc++.h>
int n,a[105],ans[105];
int main(){
scanf("%d",&n);
for (int i=1;i<=n;i++) scanf("%d",&a[i]);
for (int i=n;i>=1;i--){
for (int j=i;j>=1;j--){
if (a[j]==j){
ans[i]=j;
for (int k=j;k<i;k++) a[k]=a[k+1];
break;
}
}
if (!ans[i]){
puts("-1");
return 0;
}
}
for (int i=1;i<=n;i++) printf("%d\n",ans[i]);
} | ### Prompt
Please provide a Cpp coded solution to the problem described below:
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1
### Response
```cpp
#include <bits/stdc++.h>
int n,a[105],ans[105];
int main(){
scanf("%d",&n);
for (int i=1;i<=n;i++) scanf("%d",&a[i]);
for (int i=n;i>=1;i--){
for (int j=i;j>=1;j--){
if (a[j]==j){
ans[i]=j;
for (int k=j;k<i;k++) a[k]=a[k+1];
break;
}
}
if (!ans[i]){
puts("-1");
return 0;
}
}
for (int i=1;i<=n;i++) printf("%d\n",ans[i]);
}
``` |
#include<bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
int n; cin>>n;
vector<int> a(n+1,-1);
for (int i=1; i<=n; i++)
cin>>a[i];
stack<int> stk;
while(1) {
bool up=false;
int sz=a.size();
for (int i=sz-1; i>=1; i--)
if(a[i]==i) {
up=true;
stk.push(i);
a.erase(a.begin()+i);
break;
}
if(!up) break;
}
if(stk.size()!=n) {
cout<<-1<<"\n";
return 0;
}
while(!stk.empty())
cout<<stk.top()<<"\n", stk.pop();
return 0;
} | ### Prompt
Please formulate a Cpp solution to the following problem:
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
int n; cin>>n;
vector<int> a(n+1,-1);
for (int i=1; i<=n; i++)
cin>>a[i];
stack<int> stk;
while(1) {
bool up=false;
int sz=a.size();
for (int i=sz-1; i>=1; i--)
if(a[i]==i) {
up=true;
stk.push(i);
a.erase(a.begin()+i);
break;
}
if(!up) break;
}
if(stk.size()!=n) {
cout<<-1<<"\n";
return 0;
}
while(!stk.empty())
cout<<stk.top()<<"\n", stk.pop();
return 0;
}
``` |
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
int n; scanf("%d",&n);
vector<int> a(n);
rep(i,n) scanf("%d",&a[i]), a[i]--;
vector<int> ans(n);
for(int i=n-1;i>=0;i--){
int j;
for(j=i;j>=0;j--) if(a[j]==j) break;
if(j<0) return puts("-1"),0;
a.erase(a.begin()+j);
ans[i]=j;
}
rep(i,n) printf("%d\n",ans[i]+1);
return 0;
}
| ### Prompt
Develop a solution in CPP to the problem described below:
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1
### Response
```cpp
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
int n; scanf("%d",&n);
vector<int> a(n);
rep(i,n) scanf("%d",&a[i]), a[i]--;
vector<int> ans(n);
for(int i=n-1;i>=0;i--){
int j;
for(j=i;j>=0;j--) if(a[j]==j) break;
if(j<0) return puts("-1"),0;
a.erase(a.begin()+j);
ans[i]=j;
}
rep(i,n) printf("%d\n",ans[i]+1);
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
const int N=105;
int n,a[N];
vector<int> ans;
int main(){
scanf("%d",&n);
for (int i=1;i<=n;i++)scanf("%d",&a[i]);
for (int i=1;i<=n;i++){
int flag=0;
for (int j=n-i+1;j;j--)
if (a[j]==j){
for (int k=j;k<n-i+1;k++)a[k]=a[k+1];
ans.push_back(j);
flag=1;
break;
}
if (!flag){
puts("-1");
return 0;
}
}
for (int i=n-1;i>=0;i--)printf("%d\n",ans[i]);
} | ### Prompt
In Cpp, your task is to solve the following problem:
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
const int N=105;
int n,a[N];
vector<int> ans;
int main(){
scanf("%d",&n);
for (int i=1;i<=n;i++)scanf("%d",&a[i]);
for (int i=1;i<=n;i++){
int flag=0;
for (int j=n-i+1;j;j--)
if (a[j]==j){
for (int k=j;k<n-i+1;k++)a[k]=a[k+1];
ans.push_back(j);
flag=1;
break;
}
if (!flag){
puts("-1");
return 0;
}
}
for (int i=n-1;i>=0;i--)printf("%d\n",ans[i]);
}
``` |
#include<bits/stdc++.h>
using namespace std;
int N;
bool rec(int n, list<int>&l){
if(n == 0)return true;
auto it = l.begin();
for(int i = n; i >= 0; --i){
if(*it == i){
l.erase(it);
if(!rec(n - 1, l))return false;
cout << i << endl;
return true;
}
it++;
if(it == l.end())return false;
}
return false;
}
int main(){
cin >> N;
list<int> l;
for(int i = 0 ; i < N; ++i){
int x; cin >> x; l.push_front(x);
}
if(!rec(N, l))cout << -1 << endl;
return 0;
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int N;
bool rec(int n, list<int>&l){
if(n == 0)return true;
auto it = l.begin();
for(int i = n; i >= 0; --i){
if(*it == i){
l.erase(it);
if(!rec(n - 1, l))return false;
cout << i << endl;
return true;
}
it++;
if(it == l.end())return false;
}
return false;
}
int main(){
cin >> N;
list<int> l;
for(int i = 0 ; i < N; ++i){
int x; cin >> x; l.push_front(x);
}
if(!rec(N, l))cout << -1 << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9+7;
int main(){
int N;
cin >> N;
vector<int> b(N);
for(int i=0;i<N;i++) cin >> b.at(i);
vector<int> ans;
for(int i=N-1;i>=0;i--){
int max=-1;
for(int j=i;j>=0;j--){
if(b.at(j)==j+1){
max=j+1;
break;
}
}
//cout << max << ",";
if(max==-1){
cout << -1 << endl;
return 0;
}
ans.push_back(max);
b.erase(b.begin()+max-1);
}
for(int i=N-1;i>=0;i--) cout << ans.at(i) << endl;
return 0;
}
| ### Prompt
Your challenge is to write a cpp solution to the following problem:
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9+7;
int main(){
int N;
cin >> N;
vector<int> b(N);
for(int i=0;i<N;i++) cin >> b.at(i);
vector<int> ans;
for(int i=N-1;i>=0;i--){
int max=-1;
for(int j=i;j>=0;j--){
if(b.at(j)==j+1){
max=j+1;
break;
}
}
//cout << max << ",";
if(max==-1){
cout << -1 << endl;
return 0;
}
ans.push_back(max);
b.erase(b.begin()+max-1);
}
for(int i=N-1;i>=0;i--) cout << ans.at(i) << endl;
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
const int N = 100 + 5;
int n,b[N],ans[N];
int main()
{
cin>>n;
for (int i = 1;i <= n; ++i)
cin>>b[i];
int i = n;
for (;i;--i)
{
bool flag = 0;
for (int j = i;j;--j)
if (b[j] == j)
{
ans[i] = j;
for (int k = j + 1;k <= i;++k)
b[k - 1] = b[k];
flag = 1;
break;
}
if (!flag) break;
}
if (i)
printf("-1");
else
for (int j = 1;j <= n; ++j)
printf("%d\n",ans[j]);
} | ### Prompt
Please formulate a cpp solution to the following problem:
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
const int N = 100 + 5;
int n,b[N],ans[N];
int main()
{
cin>>n;
for (int i = 1;i <= n; ++i)
cin>>b[i];
int i = n;
for (;i;--i)
{
bool flag = 0;
for (int j = i;j;--j)
if (b[j] == j)
{
ans[i] = j;
for (int k = j + 1;k <= i;++k)
b[k - 1] = b[k];
flag = 1;
break;
}
if (!flag) break;
}
if (i)
printf("-1");
else
for (int j = 1;j <= n; ++j)
printf("%d\n",ans[j]);
}
``` |
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 7;
int n, a[maxn], ans[maxn];
bool cal() {
for (int i = 1; i <= n; ++i) {
int now = i, pos = 0;
for (int j = n; j; --j) {
if(a[j] == now) {
pos = j;
break;
}
if(!a[j]) --now;
}
if(!pos) return 0;
ans[i] = a[pos]; a[pos] = 0;
}
for (int i = 1; i <= n; ++i) printf("%d\n", ans[i]);
return 1;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
if(!cal()) printf("-1\n");
return 0;
} | ### Prompt
Your task is to create a Cpp solution to the following problem:
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 7;
int n, a[maxn], ans[maxn];
bool cal() {
for (int i = 1; i <= n; ++i) {
int now = i, pos = 0;
for (int j = n; j; --j) {
if(a[j] == now) {
pos = j;
break;
}
if(!a[j]) --now;
}
if(!pos) return 0;
ans[i] = a[pos]; a[pos] = 0;
}
for (int i = 1; i <= n; ++i) printf("%d\n", ans[i]);
return 1;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
if(!cal()) printf("-1\n");
return 0;
}
``` |
#include<iostream>
#include<vector>
using namespace std;
int a[110] = { 0 };
vector<int> v;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = n; i > 0; i--) {
if (i == a[i]) {
v.push_back(i);
for (int j = i; j <= n; j++) {
a[j] = a[j + 1];
}
i = n - 1;
}
}
if (v.size() == n) {
for (int i = v.size() - 1; i >= 0; i--) {
cout << v[i] << endl;
}
}
else {
cout << -1;
}
} | ### Prompt
Please provide a Cpp coded solution to the problem described below:
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1
### Response
```cpp
#include<iostream>
#include<vector>
using namespace std;
int a[110] = { 0 };
vector<int> v;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = n; i > 0; i--) {
if (i == a[i]) {
v.push_back(i);
for (int j = i; j <= n; j++) {
a[j] = a[j + 1];
}
i = n - 1;
}
}
if (v.size() == n) {
for (int i = v.size() - 1; i >= 0; i--) {
cout << v[i] << endl;
}
}
else {
cout << -1;
}
}
``` |
# include "iostream"
# include "cstdio"
using namespace std;
const int maxm=1e2+10;
int N,A[maxm],B[maxm];
int main(){
register int i,j,k;
register bool Find;
scanf("%d",&N);
for(i=1;i<=N;i++) scanf("%d",&A[i]);
for(i=N;i;i--){
Find=true;
for(j=i;j;j--){
if(A[j]==j){
B[i]=j;
for(k=j;k<i;k++) A[k]=A[k+1];
Find=false;
break;
}
}
if(Find){
printf("-1");
return 0;
}
}
for(i=1;i<=N;i++) printf("%d\n",B[i]);
return 0;
} | ### Prompt
Please create a solution in cpp to the following problem:
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1
### Response
```cpp
# include "iostream"
# include "cstdio"
using namespace std;
const int maxm=1e2+10;
int N,A[maxm],B[maxm];
int main(){
register int i,j,k;
register bool Find;
scanf("%d",&N);
for(i=1;i<=N;i++) scanf("%d",&A[i]);
for(i=N;i;i--){
Find=true;
for(j=i;j;j--){
if(A[j]==j){
B[i]=j;
for(k=j;k<i;k++) A[k]=A[k+1];
Find=false;
break;
}
}
if(Find){
printf("-1");
return 0;
}
}
for(i=1;i<=N;i++) printf("%d\n",B[i]);
return 0;
}
``` |
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
using namespace std;
const int N=2005;
int n;
int b[N];
int ans[N];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&b[i]);
for(int i=n;i>=1;i--){
int p=-1;
for(int j=1;j<=i;j++)
if(b[j]==j)
p=j;
ans[i]=p;
if(p==-1){
puts("-1");
return 0;
}
for(int j=p;j<=i;j++)
b[j]=b[j+1];
}
for(int i=1;i<=n;i++)
printf("%d\n",ans[i]);
}
| ### Prompt
Your challenge is to write a CPP solution to the following problem:
Snuke has an empty sequence a.
He will perform N operations on this sequence.
In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).
You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq b_i \leq N
Input
Input is given from Standard Input in the following format:
N
b_1 \dots b_N
Output
If there is no sequence of N operations after which a would be equal to b, print `-1`. If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.
Examples
Input
3
1 2 1
Output
1
1
2
Input
2
2 2
Output
-1
Input
9
1 1 1 2 2 1 2 3 2
Output
1
2
2
3
1
2
2
1
1
### Response
```cpp
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
using namespace std;
const int N=2005;
int n;
int b[N];
int ans[N];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&b[i]);
for(int i=n;i>=1;i--){
int p=-1;
for(int j=1;j<=i;j++)
if(b[j]==j)
p=j;
ans[i]=p;
if(p==-1){
puts("-1");
return 0;
}
for(int j=p;j<=i;j++)
b[j]=b[j+1];
}
for(int i=1;i<=n;i++)
printf("%d\n",ans[i]);
}
``` |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.