This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Be name khoda //
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
using namespace std;
const int maxn5 = 1e6 + 10;
bool mark[maxn5];
ll a[maxn5], b[maxn5];
queue <int> q;
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int n; cin >> n;
for(int i = 0; i < n; i++){
cin >> a[i] >> b[i];
if(a[i] - b[i] > 0 && a[i] > 1){
mark[i] = true;
q.push(i);
}
}
while(q.size()){
int i = q.front();
q.pop();
mark[i] = false;
int j = (i + 1) % n;
int w = (a[i] - b[i]) / 2 + ((a[i] - b[i]) % 2);
a[j] += w;
a[i] -= 2 * w;
//assert(a[i] >= 0 && a[i] >= b[i]);
if(a[j] - b[j] > 0 && a[j] > 1 && !mark[j]){
q.push(j);
mark[j] = true;
}
}
bool re = true;
for(int i = 0; i < n; i++)
re &= (a[i] == b[i]);
cout << (re ? "Yes" : "No") << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |