이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n;
cin >> n;
vector<long long> a(n), b(n);
long long suma = 0, sumb = 0;
for(long long i = 0; i < n; i++) {
cin >> a[i] >> b[i];
suma += a[i];
sumb += b[i];
}
if(suma < sumb) {
cout << "No" << endl;
return 0;
}
if(suma == sumb) {
for(long long i = 0; i < n; i++) {
if(a[i] != b[i]) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
}
bool f = true;
while(f) {
f = false;
for(long long i = 0; i < n; i++) {
long long extra = (a[i] - b[i]) / 2;
if(extra == 0 || b[i] > a[i])
continue;
a[i] -= extra * 2;
a[(i + 1) % n] += extra;
f = true;
}
/*for(long long i = 0; i < n; i++) {
cout << a[i] << " ";
}
cout << endl;*/
}
/*for(long long i = 0; i < n; i++) {
cout << a[i] << " " << b[i] << endl;
}*/
bool f1 = true, f2 = false;
for(long long i = 0; i < n; i++) {
if(a[i] != b[i] + 1) {
f1 = false;
}
if(a[i] >= 2)
f2 = true;
}
if(f1 && f2) {
cout << "Yes" << endl;
return 0;
}
for(long long i = 0; i < n; i++) {
if(a[i] != b[i]) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |