Submission #135846

#TimeUsernameProblemLanguageResultExecution timeMemory
135846RiscadoARemittance (JOI19_remittance)C++14
55 / 100
1085 ms20840 KiB
#include <bits/stdc++.h> const int MAX_N = 1000000; int N, A[MAX_N], B[MAX_N]; int main() { std::cin >> N; for (int i = 0; i < N; ++i) std::cin >> A[i] >> B[i]; int done_c = 0; for (int i = 0; i < N; ++i) if (A[i] == B[i]) done_c += 1; for (bool changed = true; changed;) { changed = false; for (int i = 0; i < N; ++i) if (A[i] > B[i]) { int v = A[i] - B[i]; int u = 0; if (v % 2 == 0) { A[i] -= v; done_c += 1; u = v / 2; } else { if (A[i] - v - 1 < 0) { A[i] -= v - 1; u = (v - 1) / 2; } else { A[i] -= v + 1; u = (v + 1) / 2; } } if (u == 0) continue; changed = true; int j = i + 1; if (j >= N) j = 0; if (A[j] == B[j]) done_c -= 1; A[j] += u; if (A[j] == B[j]) done_c += 1; } } if (done_c == N) printf("Yes\n"); else printf("No\n"); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...