제출 #1122522

#제출 시각아이디문제언어결과실행 시간메모리
1122522Pacybwoah송금 (JOI19_remittance)C++20
100 / 100
406 ms23888 KiB
#include<iostream> #include<vector> using namespace std; typedef long long ll; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<ll> vec(n), oa(n), ob(n); ll sum = 0; for(int i = 0; i < n; i++){ ll a, b; cin >> a >> b; vec[i] = a - b; sum += vec[i]; oa[i] = a; ob[i] = b; } int ca = 0, cb = 1, cnt = 0; while(sum > 0 && cnt <= 100 * n){ cnt++; if(vec[ca] > 0){ if(vec[ca] & 1){ if(ob[ca] == 0){ sum -= vec[ca] / 2; vec[cb] += vec[ca] / 2; vec[ca] = 1; } else{ sum -= (vec[ca] + 1) / 2; vec[cb] += (vec[ca] + 1) / 2; vec[ca] = -1; } } else{ sum -= vec[ca] / 2; vec[cb] += vec[ca] / 2; vec[ca] = 0; } } ca++; cb++; if(cb == n) cb = 0; if(ca == n) ca = 0; } if(sum != 0){ cout << "No\n"; return 0; } for(int i = 0; i < n; i++){ if(vec[i] != 0){ cout << "No\n"; return 0; } } cout << "Yes\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...