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 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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |