#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define endl '\n'
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
const int mod = 1e9 + 7;
const int N = 1e6 + 15;
const ll inf = 1e18;
int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n;
cin >> n;
vector<int> a(n), b(n);
for (int i=0;i<n;i++){
cin >> a[i] >> b[i];
}
bool go = 1;
bool flag = 1;
while (go){
go = 0;
for (int i=0;i<n;i++){
if (a[i] > b[i]){
int d = (a[i]-b[i]);
d = d/2 + d%2;
a[i] -= 2*d;
if (a[i]<0) flag = 0;
a[(i+1)%n] += d;
go=1;
}
}
for (int i=0;i<n;i++){
if (a[i] < 0) flag = 0;
}
}
for (int i=0;i<n;i++){
flag &= (a[i]==b[i]);
}
cout << (flag ? "Yes" : "No") << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |