// Muallif: Azimjon Mehmonali o'g'li
#include <bits/stdc++.h>
using namespace std;
#define int long long
const long double PI = 3.1415926535897;
const int mod = 1000000007LL;
const int INF = 1e18;
const int N = 100;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n + 1), b(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
}
pair<int, int> p{-1, -1};
for (int i = 1; i <= n; i++) {
p = max(p, make_pair(a[i] - b[i], i));
}
int t = 1000;
while (t--) {
for (int i = p.second; i < n; i++) {
if (a[i] < b[i]) continue;
int z = a[i] - b[i];
z /= 2;
a[i] -= 2 * z;
a[i + 1] += z;
}
int z = a[n] - b[n];
z /= 2;
a[n] -= 2 * z;
a[1] += z;
for (int i = 1; i < p.second; i++) {
if (a[i] < b[i]) continue;
int z = a[i] - b[i];
z /= 2;
a[i] -= 2 * z;
a[i + 1] += z;
}
}
if (a == b) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |