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 mp make_pair
#define F first
#define S second
#define printv(a, b) { \
for(auto pv : a) b << pv << " "; \
b << "\n";\
}
#define eb emplace_back
using namespace std;
typedef long long ll;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
int main(){
ios_base::sync_with_stdio(false);
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];
int now = 0;
int tmp = 0;
while(tmp < n){
int nxt = (now + 1) % n;
int cnt = max(0LL, (a[now] - b[now] + 1) / 2);
if(a[now] < cnt * 2) cnt--;
a[now] -= cnt * 2;
a[nxt] += cnt;
if(!cnt) tmp++;
else tmp = 0;
//cerr << "test " << now << " ";
//printv(a, cerr);
now = (now + 1) % n;
}
for(int i = 0; i < n; i++){
if(a[i] != b[i]){
cout << "No\n";
return 0;
}
}
cout << "Yes\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... |