# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
227249 | alexandra_udristoiu | Remittance (JOI19_remittance) | C++14 | 383 ms | 28908 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<iostream>
#include<cstdio>
#define DIM 1000005
using namespace std;
int n, i, ok, x;
int a[DIM], b[DIM];
long long sum, sum2;
int nxt(int i){
if(i == n){
return 1;
}
return i + 1;
}
int main(){
scanf("%d", &n);
ok = 1;
for(i = 1; i <= n; i++){
scanf("%d%d", &a[i], &b[i]);
if(a[i] != 0){
ok = 0;
}
sum2 += b[i];
}
if(sum2 == 0 && ok == 0){
cout<<"No";
return 0;
}
do{
ok = 1;
for(i = 1; i <= n; i++){
if(a[i] != b[i]){
ok = 0;
if(a[i] > b[i]){
x = (a[i] - b[i]) / 2 + (a[i] - b[i]) % 2;
a[ nxt(i) ] += x;
a[i] -= 2 * x;
}
}
}
sum = 0;
for(i = 1; i <= n; i++){
sum += a[i];
}
if(sum < sum2){
break;
}
}while(ok == 0);
if(ok == 1){
cout<<"Yes";
}
else{
cout<<"No";
}
}
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... |