#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
const int MAXN = 3e5 + 10;
const int MOD = 1e9 + 7;
#define int long long
int rnd(int x, int y) {
int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
void solve(int tc) {
int n; cin >> n;
vector<int> a(n), b(n);
for(int i=0; i<n; i++) cin >> a[i] >> b[i];
for(int i=0; i<1e7; i++) {
for(int j=0; j<n; j++) {
if(a[j] > b[j]) {
int c = (a[j] - b[j] + 1) / 2;
c = max(c, 0ll);
c = min(c, a[j] / 2);
a[j] -= 2 * c;
a[(j+1) % n] += c;
}
}
}
for(int i=0; i<n; i++) {
if(a[i] != b[i]) {
cout << "No\n"; return;
}
}
cout << "Yes\n";
}
int32_t main(){
ios::sync_with_stdio(0); cin.tie(0);
int t = 1; //cin >> t;
for(int i=1; i<=t; i++) solve(i);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
112 ms |
204 KB |
Output is correct |
2 |
Correct |
33 ms |
204 KB |
Output is correct |
3 |
Correct |
28 ms |
324 KB |
Output is correct |
4 |
Correct |
37 ms |
204 KB |
Output is correct |
5 |
Correct |
75 ms |
296 KB |
Output is correct |
6 |
Correct |
88 ms |
296 KB |
Output is correct |
7 |
Correct |
86 ms |
304 KB |
Output is correct |
8 |
Correct |
26 ms |
204 KB |
Output is correct |
9 |
Correct |
60 ms |
304 KB |
Output is correct |
10 |
Correct |
67 ms |
304 KB |
Output is correct |
11 |
Correct |
90 ms |
300 KB |
Output is correct |
12 |
Correct |
30 ms |
204 KB |
Output is correct |
13 |
Correct |
52 ms |
204 KB |
Output is correct |
14 |
Correct |
68 ms |
296 KB |
Output is correct |
15 |
Correct |
95 ms |
292 KB |
Output is correct |
16 |
Correct |
55 ms |
204 KB |
Output is correct |
17 |
Correct |
56 ms |
204 KB |
Output is correct |
18 |
Correct |
94 ms |
292 KB |
Output is correct |
19 |
Correct |
86 ms |
292 KB |
Output is correct |
20 |
Correct |
354 ms |
296 KB |
Output is correct |
21 |
Correct |
345 ms |
296 KB |
Output is correct |
22 |
Correct |
91 ms |
308 KB |
Output is correct |
23 |
Correct |
293 ms |
292 KB |
Output is correct |
24 |
Correct |
83 ms |
296 KB |
Output is correct |
25 |
Correct |
84 ms |
296 KB |
Output is correct |
26 |
Correct |
352 ms |
204 KB |
Output is correct |
27 |
Correct |
89 ms |
204 KB |
Output is correct |
28 |
Correct |
85 ms |
204 KB |
Output is correct |
29 |
Correct |
87 ms |
296 KB |
Output is correct |
30 |
Correct |
115 ms |
292 KB |
Output is correct |
31 |
Correct |
349 ms |
300 KB |
Output is correct |
32 |
Correct |
85 ms |
300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
112 ms |
204 KB |
Output is correct |
2 |
Correct |
33 ms |
204 KB |
Output is correct |
3 |
Correct |
28 ms |
324 KB |
Output is correct |
4 |
Correct |
37 ms |
204 KB |
Output is correct |
5 |
Correct |
75 ms |
296 KB |
Output is correct |
6 |
Correct |
88 ms |
296 KB |
Output is correct |
7 |
Correct |
86 ms |
304 KB |
Output is correct |
8 |
Correct |
26 ms |
204 KB |
Output is correct |
9 |
Correct |
60 ms |
304 KB |
Output is correct |
10 |
Correct |
67 ms |
304 KB |
Output is correct |
11 |
Correct |
90 ms |
300 KB |
Output is correct |
12 |
Correct |
30 ms |
204 KB |
Output is correct |
13 |
Correct |
52 ms |
204 KB |
Output is correct |
14 |
Correct |
68 ms |
296 KB |
Output is correct |
15 |
Correct |
95 ms |
292 KB |
Output is correct |
16 |
Correct |
55 ms |
204 KB |
Output is correct |
17 |
Correct |
56 ms |
204 KB |
Output is correct |
18 |
Correct |
94 ms |
292 KB |
Output is correct |
19 |
Correct |
86 ms |
292 KB |
Output is correct |
20 |
Correct |
354 ms |
296 KB |
Output is correct |
21 |
Correct |
345 ms |
296 KB |
Output is correct |
22 |
Correct |
91 ms |
308 KB |
Output is correct |
23 |
Correct |
293 ms |
292 KB |
Output is correct |
24 |
Correct |
83 ms |
296 KB |
Output is correct |
25 |
Correct |
84 ms |
296 KB |
Output is correct |
26 |
Correct |
352 ms |
204 KB |
Output is correct |
27 |
Correct |
89 ms |
204 KB |
Output is correct |
28 |
Correct |
85 ms |
204 KB |
Output is correct |
29 |
Correct |
87 ms |
296 KB |
Output is correct |
30 |
Correct |
115 ms |
292 KB |
Output is correct |
31 |
Correct |
349 ms |
300 KB |
Output is correct |
32 |
Correct |
85 ms |
300 KB |
Output is correct |
33 |
Correct |
338 ms |
296 KB |
Output is correct |
34 |
Correct |
289 ms |
204 KB |
Output is correct |
35 |
Correct |
283 ms |
292 KB |
Output is correct |
36 |
Correct |
35 ms |
308 KB |
Output is correct |
37 |
Correct |
312 ms |
204 KB |
Output is correct |
38 |
Correct |
27 ms |
312 KB |
Output is correct |
39 |
Correct |
64 ms |
204 KB |
Output is correct |
40 |
Correct |
351 ms |
300 KB |
Output is correct |
41 |
Correct |
286 ms |
292 KB |
Output is correct |
42 |
Correct |
26 ms |
204 KB |
Output is correct |
43 |
Correct |
64 ms |
204 KB |
Output is correct |
44 |
Correct |
282 ms |
204 KB |
Output is correct |
45 |
Correct |
316 ms |
300 KB |
Output is correct |
46 |
Correct |
31 ms |
204 KB |
Output is correct |
47 |
Correct |
63 ms |
324 KB |
Output is correct |
48 |
Correct |
288 ms |
292 KB |
Output is correct |
49 |
Correct |
303 ms |
300 KB |
Output is correct |
50 |
Correct |
98 ms |
300 KB |
Output is correct |
51 |
Correct |
988 ms |
296 KB |
Output is correct |
52 |
Correct |
58 ms |
204 KB |
Output is correct |
53 |
Correct |
904 ms |
296 KB |
Output is correct |
54 |
Correct |
340 ms |
292 KB |
Output is correct |
55 |
Correct |
282 ms |
300 KB |
Output is correct |
56 |
Execution timed out |
1022 ms |
296 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
112 ms |
204 KB |
Output is correct |
2 |
Correct |
33 ms |
204 KB |
Output is correct |
3 |
Correct |
28 ms |
324 KB |
Output is correct |
4 |
Correct |
37 ms |
204 KB |
Output is correct |
5 |
Correct |
75 ms |
296 KB |
Output is correct |
6 |
Correct |
88 ms |
296 KB |
Output is correct |
7 |
Correct |
86 ms |
304 KB |
Output is correct |
8 |
Correct |
26 ms |
204 KB |
Output is correct |
9 |
Correct |
60 ms |
304 KB |
Output is correct |
10 |
Correct |
67 ms |
304 KB |
Output is correct |
11 |
Correct |
90 ms |
300 KB |
Output is correct |
12 |
Correct |
30 ms |
204 KB |
Output is correct |
13 |
Correct |
52 ms |
204 KB |
Output is correct |
14 |
Correct |
68 ms |
296 KB |
Output is correct |
15 |
Correct |
95 ms |
292 KB |
Output is correct |
16 |
Correct |
55 ms |
204 KB |
Output is correct |
17 |
Correct |
56 ms |
204 KB |
Output is correct |
18 |
Correct |
94 ms |
292 KB |
Output is correct |
19 |
Correct |
86 ms |
292 KB |
Output is correct |
20 |
Correct |
354 ms |
296 KB |
Output is correct |
21 |
Correct |
345 ms |
296 KB |
Output is correct |
22 |
Correct |
91 ms |
308 KB |
Output is correct |
23 |
Correct |
293 ms |
292 KB |
Output is correct |
24 |
Correct |
83 ms |
296 KB |
Output is correct |
25 |
Correct |
84 ms |
296 KB |
Output is correct |
26 |
Correct |
352 ms |
204 KB |
Output is correct |
27 |
Correct |
89 ms |
204 KB |
Output is correct |
28 |
Correct |
85 ms |
204 KB |
Output is correct |
29 |
Correct |
87 ms |
296 KB |
Output is correct |
30 |
Correct |
115 ms |
292 KB |
Output is correct |
31 |
Correct |
349 ms |
300 KB |
Output is correct |
32 |
Correct |
85 ms |
300 KB |
Output is correct |
33 |
Correct |
338 ms |
296 KB |
Output is correct |
34 |
Correct |
289 ms |
204 KB |
Output is correct |
35 |
Correct |
283 ms |
292 KB |
Output is correct |
36 |
Correct |
35 ms |
308 KB |
Output is correct |
37 |
Correct |
312 ms |
204 KB |
Output is correct |
38 |
Correct |
27 ms |
312 KB |
Output is correct |
39 |
Correct |
64 ms |
204 KB |
Output is correct |
40 |
Correct |
351 ms |
300 KB |
Output is correct |
41 |
Correct |
286 ms |
292 KB |
Output is correct |
42 |
Correct |
26 ms |
204 KB |
Output is correct |
43 |
Correct |
64 ms |
204 KB |
Output is correct |
44 |
Correct |
282 ms |
204 KB |
Output is correct |
45 |
Correct |
316 ms |
300 KB |
Output is correct |
46 |
Correct |
31 ms |
204 KB |
Output is correct |
47 |
Correct |
63 ms |
324 KB |
Output is correct |
48 |
Correct |
288 ms |
292 KB |
Output is correct |
49 |
Correct |
303 ms |
300 KB |
Output is correct |
50 |
Correct |
98 ms |
300 KB |
Output is correct |
51 |
Correct |
988 ms |
296 KB |
Output is correct |
52 |
Correct |
58 ms |
204 KB |
Output is correct |
53 |
Correct |
904 ms |
296 KB |
Output is correct |
54 |
Correct |
340 ms |
292 KB |
Output is correct |
55 |
Correct |
282 ms |
300 KB |
Output is correct |
56 |
Execution timed out |
1022 ms |
296 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |