Submission #904827

#TimeUsernameProblemLanguageResultExecution timeMemory
904827vjudge1Remittance (JOI19_remittance)C++17
100 / 100
247 ms36468 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define pii pair<int, int> #define F first #define S second #define pb push_back #define fast ios::sync_with_stdio(false), cin.tie(NULL) const int MAXN = 2e5 + 5; const int MOD = 1e9 + 7; const int INF = 1e18; const int SQ = 350; const int LG = 23; signed main() { fast; int n; cin >> n; int a[n], b[n]; for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; bool f1 = 0, f2 = 0; for (int i = 0; i < n; i++) if (a[i]) f1 = 1; for (int i = 0; i < n; i++) if (b[i]) f2 = 1; if (!f1 && !f2) return cout << "Yes", 0; if (f1 ^ f2) return cout << "No", 0; while (true) { bool good = 1; for (int i = 0; i < n; i++) if (a[i] > b[i]) good = 0; if (good) break; for (int i = 0; i < n; i++) if (a[i] > b[i]) { int x = (a[i] - b[i] + 1) >> 1; a[i] -= x * 2; a[(i + 1) % n] += x; } } bool good = 1; for (int i = 0; i < n; i++) if (a[i] != b[i]) good = 0; if (good) cout << "Yes"; else cout << "No"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...