# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
555254 | nafis_shifat | Remittance (JOI19_remittance) | C++17 | 298 ms | 28404 KiB |
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 ll long long
#define pii pair<int,int>
using namespace std;
const int mxn=1e6+5;
const int inf=1e9;
int a[mxn], b[mxn];
int n;
void process() {
for(int i = 0; i < n; i++) {
int nxt = (i + 1) % n;
int rem = (a[i] - b[i]) / 2;
if(rem <= 0) continue;
a[nxt] += rem;
a[i] -= 2 * rem;
}
}
int main() {
cin >> n;
ll bs = 0;
ll as = 0;
for(int i = 0; i < n; i++) {
scanf("%d%d", &a[i], &b[i]);
bs += b[i];
as += a[i];
}
if(as && !bs) {
cout<<"No"<<endl;
return 0;
}
for(int i = 0; i < 60; i++) process();
bool f1 = true, f2 = true;
for(int i = 0; i < n; i++) {
f1 = f1 && (a[i] == b[i]);
f2 = f2 && (a[i] == b[i] + 1);
}
if(f1 || f2) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |