제출 #717999

#제출 시각아이디문제언어결과실행 시간메모리
717999Radin_Zahedi2송금 (JOI19_remittance)C++17
100 / 100
427 ms28584 KiB
#include<bits/stdc++.h> #pragma GCC optimize("O2") using namespace std; #define pb push_back #define mp make_pair #define fi first #define se second #define sz(x) (int)x.size() #define endl '\n' int n; const int N = 1e6 + 5; int a[N]; int b[N]; void input() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; } } int cgive(int i) { int d = a[i] - b[i]; if (d % 2 == 0) { return d / 2; } if (a[i] >= d + 1) { return (d + 1) / 2; } return (d - 1) / 2; } void give(int i, int x) { int ne = i + 1; if (ne == n) { ne = 0; } a[i] -= 2 * x; a[ne] += x; } void solve() { for (int t = 0; t < 60; t++) { for (int i = 0; i < n; i++) { if (a[i] > b[i]) { give(i, cgive(i)); } } } for (int i = 0; i < n; i++) { if (a[i] != b[i]) { cout << "No"; return; } } cout << "Yes"; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); input(); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...