제출 #870393

#제출 시각아이디문제언어결과실행 시간메모리
870393serifefedartar송금 (JOI19_remittance)C++17
100 / 100
164 ms28500 KiB
#include <bits/stdc++.h>
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 1e9+9;
const ll LOGN = 20; 
const ll MAXN = 1e6 + 100;

int A[MAXN], B[MAXN];
int main() {
	fast
	int N;
	cin >> N;

	for (int i = 0; i < N; i++)
		cin >> A[i] >> B[i];

	bool B_zero = true, A_zero = true;
	for (int i = 1; i <= N; i++) {
		B_zero &= (B[i] == 0);
		A_zero &= (A[i] == 0);
	}


	if (B_zero && A_zero)
		cout << "Yes\n";
	else if (B_zero != A_zero)
		cout << "No\n";
	else {
		bool check = true;
		while (check) {
			check = false;
			for (int i = 0; i < N; i++) {
				if (A[i] > B[i]) {
					int excess = (A[i] - B[i] + 1) / 2;
					A[i] -= excess * 2;
					A[(i+1) % N] += excess;
					check = true;
				}
			}
		}

		for (int i = 0; i < N; i++) {
			if (A[i] != B[i]) {
				cout << "No\n";
				return 0;
			}
		}
		cout << "Yes\n";
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...