Submission #756317

#TimeUsernameProblemLanguageResultExecution timeMemory
756317hanifchdnRemittance (JOI19_remittance)C++17
0 / 100
1080 ms340 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define fi first #define se second int a[1000005], b[1000005]; bool vis[1000005]; queue<int> q; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; if (a[i] > b[i] and a[i] > 1) vis[i] = 1, q.push(i); } while (!q.empty()) { int x = q.front(); q.pop(); int tmp = a[x] - b[x]; if (tmp % 2 and b[x] > 0) tmp++; vis[x] = 0, a[(x + 1) % n] += tmp / 2, a[x] -= tmp - tmp % 2; if (!vis[(x + 1) % n] and a[(x + 1) % n] > b[(x + 1) % n]) vis[(x + 1) % n] = 1, q.push((x + 1) % n); } bool ans = 1; for (int i = 0; i < n; i++) if (a[i] != b[i]) ans = 0; if (ans) cout << "Yes\n"; else cout << "No\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...