View Code of Problem 4067

#include<iostream>
using namespace std;
long long  a[10000100];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	int flag = 0;
	for (int i = n - 1; i >= 1; i--) {
		if (a[i] > a[i - 1]) {
			if ((a[i] - 1) >= 0 && (a[i] - 1) >= (a[i - 1] + 1)) {
				flag = 1;
				break;
			} else {
				if ((a[i] - 1) >= 0) {
					a[i] = a[i] - 1;
					a[i - 1] = a[i - 1] + 1;
				}

			}
		}
	}
	if (flag == 1) {
		cout << "No\n";
		return 0;
	}
	for (int i = 0; i < n - 1; i++) {
		if (a[i] <= a[i + 1]) {
			cout << "NO\n";
			return 0;
		}
	}
	cout << "YES\n";

}

Double click to view unformatted code.


Back to problem 4067