This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define vec vector
#define int long long
int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vec<int> a(n);
	vec<int> b(n);
	for(int i = 0; i<n; i++) {
		cin >> a[i];
		cin >> b[i];
	}
	bool con = true;
	while(con) {
		con = false;
		for(int i = 0; i<n; i++) {
			int dif = (a[i]-b[i])/2;
			if(dif > 0) {
				con = true;
				a[(i+1)%n] += dif;
				a[i] -= dif * 2;
			}
		}
	}
	if(a==b) cout << "Yes" << '\n';
	else {
		bool l2 = false;
		for(int i = 0; i<n; i++) {
			if(a[i] != b[i]+1) {
				cout << "No" << '\n';
				return 0;
			}
			l2 |= a[i] >= 2;
		}
		if(l2) {
			cout << "Yes" << '\n';
		}
		else {
			cout << "No" << '\n';
		}
	}
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |