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>
using namespace std;
#define int long long
#define double long double
#define FOR(i, l, r, d) for(int i=(l); i<=(r); i+=(d))
#define szof(x) ((int)(x).size())
#define vi vector<int>
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mkp make_pair
const int INF = INT_MAX;
const int LNF = INF*INF;
const int MOD = 1000000007;
const int MAX = 1000010;
int n;
int arr[MAX], target[MAX];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n;
FOR(i, 0, n - 1, 1){
cin>>arr[i]>>target[i];
}
int ptr = 0;
int cnt = 0;
while(cnt < n){
int nxt = (ptr + 1) % n;
int send = max((int)0, arr[ptr] - target[ptr] + 1) / 2;
if(arr[ptr] < 2 * send) send--;
arr[ptr] -= 2 * send;
arr[nxt] += send;
if(send == 0) cnt++;
else cnt = 0;
/*
cerr<<"ptr = "<<ptr<<", send = "<<send<<", arr = ";
FOR(i, 0, n-1, 1){
cerr<<arr[i]<<' ';
}
cerr<<endl;
*/
ptr = (ptr + 1) % n;
}
bool res = 1;
FOR(i, 0, n - 1, 1){
if(arr[i] != target[i]) res = 0;
}
if(res) cout<<"Yes"<<'\n';
else cout<<"No"<<'\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |