#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |