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 <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n; cin >> n;
vector<ll> A(n), B(n);
for(int i = 0; i < n; i++) cin >> A[i] >> B[i];
queue<int> Q;
vector<bool> inQ(n, 0);
for(int i = 0; i < n; i++) if(A[i] > B[i]+1) inQ[i] = 1, Q.push(i);
while(!Q.empty()){
int i = Q.front(); Q.pop();
inQ[i] = 0;
int x = (A[i]-B[i])/2;
A[i] = B[i]+(A[i]-B[i])%2;
int j = (i+1)%n;
if(A[j] <= B[j]+1 && A[j]+x > B[j]+1 && !inQ[j]) inQ[j] = 1, Q.push(j);
A[j]+=x;
}
bool a = 1, b = 1;
for(int i = 0; i < n; i++){
if(A[i] != B[i]) a = 0;
if(A[i] != B[i]+1) b = 0;
}
cout << (a|b?"Yes\n":"No\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... |