#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1010101;
const ll INF = 1e13 + 10;
int n; ll a[N], b[N];
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin >> n;
for (int i = 0; i < n; i++) {
ll x, y; cin >> x >> y;
a[i] = b[i] = x - y;
}
ll L = -1, R = 1e9 + 10;
while (L < R) {
ll M = (L + R) >> 1;
for (int i = 0; i < n; i++)
a[i] = b[i];
int r = 0;
for (int i = n - 1; i > 0; i--) {
ll d = M - a[i];
a[i] += d;
a[i - 1] -= 2 * d;
if (a[i] < -INF) {
r = 1;
break;
}
if (a[i] > INF) {
r = 2;
break;
}
}
if (r == 1)
R = M;
else if (r == 2)
L = M + 1;
else {
if (a[0] <= M)
R = M;
else
L = M + 1;
}
}
for (int i = 0; i < n; i++)
a[i] = b[i];
for (int i = n - 1; i > 0; i--) {
ll d = L - a[i];
a[i] += d;
a[i - 1] -= 2 * d;
if (a[i - 1] < -INF || a[i - 1] > INF) {
return !(cout << "No");
}
}
if (a[0] != L)
return !(cout << "No");
for (int i = n - 1; i >= 0; i--) {
L = 2 * L - b[i];
if (L < 0)
return !(cout << "No");
}
cout << "Yes";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
224 KB |
Output is correct |
2 |
Correct |
1 ms |
220 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
220 KB |
Output is correct |
11 |
Correct |
1 ms |
352 KB |
Output is correct |
12 |
Correct |
1 ms |
224 KB |
Output is correct |
13 |
Correct |
1 ms |
224 KB |
Output is correct |
14 |
Correct |
1 ms |
224 KB |
Output is correct |
15 |
Correct |
0 ms |
336 KB |
Output is correct |
16 |
Correct |
0 ms |
224 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
224 KB |
Output is correct |
19 |
Correct |
1 ms |
224 KB |
Output is correct |
20 |
Incorrect |
1 ms |
224 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
224 KB |
Output is correct |
2 |
Correct |
1 ms |
220 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
220 KB |
Output is correct |
11 |
Correct |
1 ms |
352 KB |
Output is correct |
12 |
Correct |
1 ms |
224 KB |
Output is correct |
13 |
Correct |
1 ms |
224 KB |
Output is correct |
14 |
Correct |
1 ms |
224 KB |
Output is correct |
15 |
Correct |
0 ms |
336 KB |
Output is correct |
16 |
Correct |
0 ms |
224 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
224 KB |
Output is correct |
19 |
Correct |
1 ms |
224 KB |
Output is correct |
20 |
Incorrect |
1 ms |
224 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
224 KB |
Output is correct |
2 |
Correct |
1 ms |
220 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
220 KB |
Output is correct |
11 |
Correct |
1 ms |
352 KB |
Output is correct |
12 |
Correct |
1 ms |
224 KB |
Output is correct |
13 |
Correct |
1 ms |
224 KB |
Output is correct |
14 |
Correct |
1 ms |
224 KB |
Output is correct |
15 |
Correct |
0 ms |
336 KB |
Output is correct |
16 |
Correct |
0 ms |
224 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
224 KB |
Output is correct |
19 |
Correct |
1 ms |
224 KB |
Output is correct |
20 |
Incorrect |
1 ms |
224 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |