This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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);
ll sum = 0;
for(int i = 0; i < n; i++){
ll a, b;
cin >> a >> b;
vec[i] = a - b;
sum += vec[i];
}
int ca = 0, cb = 1;
while(sum > 0){
if(vec[ca] > 0){
if(vec[ca] & 1){
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |