#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort(all((x)))
#define X first
#define Y second
#define Mp make_pair
#define sep ' '
#define endl '\n'
#define debug(x) cerr << #x << " = " << x << endl
#define SZ(x) ll(x.size())
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define set_random mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll poww(ll a, ll b, ll md) {
return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}
set_random;
const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;
ll n , cnt , A[MAXN] , B[MAXN];
queue<ll> q;
int main() {
fast_io;
cin >> n;
for(ll i = 0 ; i < n ; i++){
cin >> A[i] >> B[i];
if(A[i] > B[i]) q.push(i);
}
while(!q.empty() && cnt <= 3e7){
ll i = q.front() , j = (i + 1) % n , t = (A[i] - B[i] + 1) / 2 , inqueue = 0;
q.pop();
if(A[i] - t * 2 < 0){
q.push(i);
cnt++;
continue;
}
if(A[j] > B[j]) inqueue = 1;
A[i] -= t * 2;
A[j] += t;
if(A[i] > B[i]) q.push(i);
if(!inqueue && A[j] > B[j]){
q.push(j);
}
cnt++;
}
for(ll i = 0 ; i < n ; i++){
if(A[i] != B[i]) return cout << "No" << endl , 0;
}
cout << "Yes" << endl;
return 0;
}
/*
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
1 ms |
376 KB |
Output is correct |
16 |
Correct |
521 ms |
396 KB |
Output is correct |
17 |
Correct |
521 ms |
416 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
514 ms |
400 KB |
Output is correct |
20 |
Correct |
514 ms |
376 KB |
Output is correct |
21 |
Correct |
511 ms |
432 KB |
Output is correct |
22 |
Correct |
507 ms |
440 KB |
Output is correct |
23 |
Correct |
510 ms |
504 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
509 ms |
504 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
3 ms |
376 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
3 ms |
376 KB |
Output is correct |
31 |
Correct |
509 ms |
400 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
1 ms |
376 KB |
Output is correct |
16 |
Correct |
521 ms |
396 KB |
Output is correct |
17 |
Correct |
521 ms |
416 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
514 ms |
400 KB |
Output is correct |
20 |
Correct |
514 ms |
376 KB |
Output is correct |
21 |
Correct |
511 ms |
432 KB |
Output is correct |
22 |
Correct |
507 ms |
440 KB |
Output is correct |
23 |
Correct |
510 ms |
504 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
509 ms |
504 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
3 ms |
376 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
3 ms |
376 KB |
Output is correct |
31 |
Correct |
509 ms |
400 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |
33 |
Correct |
3 ms |
376 KB |
Output is correct |
34 |
Correct |
2 ms |
376 KB |
Output is correct |
35 |
Correct |
2 ms |
376 KB |
Output is correct |
36 |
Correct |
2 ms |
376 KB |
Output is correct |
37 |
Correct |
2 ms |
376 KB |
Output is correct |
38 |
Correct |
3 ms |
376 KB |
Output is correct |
39 |
Correct |
1 ms |
376 KB |
Output is correct |
40 |
Correct |
2 ms |
376 KB |
Output is correct |
41 |
Correct |
3 ms |
312 KB |
Output is correct |
42 |
Correct |
2 ms |
376 KB |
Output is correct |
43 |
Correct |
3 ms |
376 KB |
Output is correct |
44 |
Correct |
3 ms |
376 KB |
Output is correct |
45 |
Correct |
511 ms |
404 KB |
Output is correct |
46 |
Correct |
2 ms |
376 KB |
Output is correct |
47 |
Correct |
2 ms |
376 KB |
Output is correct |
48 |
Correct |
17 ms |
376 KB |
Output is correct |
49 |
Correct |
3 ms |
380 KB |
Output is correct |
50 |
Correct |
514 ms |
400 KB |
Output is correct |
51 |
Correct |
614 ms |
376 KB |
Output is correct |
52 |
Correct |
605 ms |
504 KB |
Output is correct |
53 |
Correct |
514 ms |
400 KB |
Output is correct |
54 |
Correct |
2 ms |
376 KB |
Output is correct |
55 |
Correct |
2 ms |
376 KB |
Output is correct |
56 |
Correct |
507 ms |
412 KB |
Output is correct |
57 |
Correct |
2 ms |
376 KB |
Output is correct |
58 |
Correct |
2 ms |
376 KB |
Output is correct |
59 |
Correct |
2 ms |
376 KB |
Output is correct |
60 |
Correct |
2 ms |
376 KB |
Output is correct |
61 |
Correct |
508 ms |
380 KB |
Output is correct |
62 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
1 ms |
376 KB |
Output is correct |
16 |
Correct |
521 ms |
396 KB |
Output is correct |
17 |
Correct |
521 ms |
416 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
514 ms |
400 KB |
Output is correct |
20 |
Correct |
514 ms |
376 KB |
Output is correct |
21 |
Correct |
511 ms |
432 KB |
Output is correct |
22 |
Correct |
507 ms |
440 KB |
Output is correct |
23 |
Correct |
510 ms |
504 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
509 ms |
504 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
3 ms |
376 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
3 ms |
376 KB |
Output is correct |
31 |
Correct |
509 ms |
400 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |
33 |
Correct |
3 ms |
376 KB |
Output is correct |
34 |
Correct |
2 ms |
376 KB |
Output is correct |
35 |
Correct |
2 ms |
376 KB |
Output is correct |
36 |
Correct |
2 ms |
376 KB |
Output is correct |
37 |
Correct |
2 ms |
376 KB |
Output is correct |
38 |
Correct |
3 ms |
376 KB |
Output is correct |
39 |
Correct |
1 ms |
376 KB |
Output is correct |
40 |
Correct |
2 ms |
376 KB |
Output is correct |
41 |
Correct |
3 ms |
312 KB |
Output is correct |
42 |
Correct |
2 ms |
376 KB |
Output is correct |
43 |
Correct |
3 ms |
376 KB |
Output is correct |
44 |
Correct |
3 ms |
376 KB |
Output is correct |
45 |
Correct |
511 ms |
404 KB |
Output is correct |
46 |
Correct |
2 ms |
376 KB |
Output is correct |
47 |
Correct |
2 ms |
376 KB |
Output is correct |
48 |
Correct |
17 ms |
376 KB |
Output is correct |
49 |
Correct |
3 ms |
380 KB |
Output is correct |
50 |
Correct |
514 ms |
400 KB |
Output is correct |
51 |
Correct |
614 ms |
376 KB |
Output is correct |
52 |
Correct |
605 ms |
504 KB |
Output is correct |
53 |
Correct |
514 ms |
400 KB |
Output is correct |
54 |
Correct |
2 ms |
376 KB |
Output is correct |
55 |
Correct |
2 ms |
376 KB |
Output is correct |
56 |
Correct |
507 ms |
412 KB |
Output is correct |
57 |
Correct |
2 ms |
376 KB |
Output is correct |
58 |
Correct |
2 ms |
376 KB |
Output is correct |
59 |
Correct |
2 ms |
376 KB |
Output is correct |
60 |
Correct |
2 ms |
376 KB |
Output is correct |
61 |
Correct |
508 ms |
380 KB |
Output is correct |
62 |
Correct |
2 ms |
376 KB |
Output is correct |
63 |
Correct |
353 ms |
39516 KB |
Output is correct |
64 |
Correct |
178 ms |
22520 KB |
Output is correct |
65 |
Correct |
476 ms |
42072 KB |
Output is correct |
66 |
Correct |
177 ms |
24028 KB |
Output is correct |
67 |
Correct |
215 ms |
27128 KB |
Output is correct |
68 |
Correct |
274 ms |
29980 KB |
Output is correct |
69 |
Correct |
512 ms |
41592 KB |
Output is correct |
70 |
Correct |
682 ms |
24036 KB |
Output is correct |
71 |
Correct |
720 ms |
27128 KB |
Output is correct |
72 |
Correct |
265 ms |
29868 KB |
Output is correct |
73 |
Correct |
882 ms |
41524 KB |
Output is correct |
74 |
Correct |
702 ms |
24172 KB |
Output is correct |
75 |
Correct |
735 ms |
27144 KB |
Output is correct |
76 |
Correct |
749 ms |
29780 KB |
Output is correct |
77 |
Correct |
526 ms |
41452 KB |
Output is correct |
78 |
Correct |
747 ms |
35952 KB |
Output is correct |
79 |
Correct |
797 ms |
35820 KB |
Output is correct |
80 |
Correct |
274 ms |
35844 KB |
Output is correct |
81 |
Correct |
299 ms |
35864 KB |
Output is correct |
82 |
Correct |
709 ms |
28392 KB |
Output is correct |
83 |
Correct |
142 ms |
19932 KB |
Output is correct |
84 |
Correct |
143 ms |
19856 KB |
Output is correct |
85 |
Correct |
370 ms |
44680 KB |
Output is correct |
86 |
Correct |
366 ms |
44680 KB |
Output is correct |
87 |
Correct |
840 ms |
37128 KB |
Output is correct |
88 |
Correct |
282 ms |
36992 KB |
Output is correct |