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>
using namespace std;
int const nmax = 1000000;
int a[5 + nmax], b[5 + nmax];
int main() {
std::ios_base::sync_with_stdio(0);
std::cin.tie(0);
int n;
std::cin >> n;
for(int i = 0;i < n; i++)
std::cin >> a[i] >> b[i];
bool all0 = true;
for(int i = 0;i < n; i++) {
if(b[i] > 0)
all0 = false;
}
if(all0 == true) {
std::cout << "Yes\n";
return 0;
}
while(true) {
bool complete = true;
for(int i = 0;i < n; i++) {
if(a[i] > b[i]) {
int aux = (a[i] - b[i] + 1) / 2;
a[i] -= aux * 2;
a[(i + 1) % n] += aux;
if(aux > 0)
complete = false;
}
}
if(complete == true)
break;
}
bool ans = false;
for(int i = 0;i < n; i++) {
if(b[i] > 0)
ans = true;
}
for(int i = 0;i < n; i++) {
if(a[i] != b[i])
ans = false;
}
if(ans == true)
std::cout << "Yes\n";
else
std::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... |