#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = (int)1e6 + 10;
ll A[N], B[N];
int main(){
fastIO;
int n;
cin >> n;
for(int i = 0 ; i < n ; i ++ ){
cin >> A[i] >> B[i];
}
ll sa = 0, sb = 0;
for(int i =0 ; i < n; i ++ )
sa += A[i], sb += B[i];
if(sb == 0){
if(sa == 0){
cout << "Yes\n";
}
else{
cout << "No\n";
}
return 0;
}
ll t;
bool h = true;
while(h){
h=false;
for(int i = 0 ; i < n; i ++ ){
if(A[i]>B[i]+1){
t=(A[i]-B[i])/2ll;
A[i]-=2ll*t;
A[(i+1)%n]+=t;
h=true;
}
}
}
for(int i = 0 ; i < n; i ++ ){
if(A[i] != B[i]){
cout << "No\n";
return 0;
}
}
cout << "Yes\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |