제출 #477148

#제출 시각아이디문제언어결과실행 시간메모리
477148jesus_coconutRemittance (JOI19_remittance)C++17
100 / 100
289 ms36440 KiB
#include <bits/stdc++.h> #define all(a) begin(a), end(a) #define F first #define S second #define pb push_back using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; int const MOD = 1e9 + 7; int const N = 500009; void solve() { int n; cin >> n; vector<ll> a(n), b(n); for (int i = 0; i < n; ++i) cin >> a[i] >> b[i]; if (all_of(all(b), [](ll x) { return x == 0; })) { if (all_of(all(a), [](ll x) { return x == 0; })) { cout << "Yes\n"; } else cout << "No\n"; return; } while (true) { bool rep = false; for (int i = 0; i < n; ++i) { if (a[i] > b[i]) { ll diff = (a[i] - b[i] + 1) / 2; a[i] -= 2 * diff; a[(i+1) % n] += diff; rep = true; } } if ([&]{ for (int i = 0; i < n; ++i) { if (a[i] != b[i]) return false; } return true; }()) { cout << "Yes\n"; return; } if (!rep) { cout << "No\n"; return; } } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...