#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include <cassert>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric> //gcd(a,b)
#include<bitset>
using namespace std;
#define ll long long/
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-loops")
using namespace std;
#define int long long
const int mod=1e9+7,mxn=1e6+5,lg=30,inf=1e18,minf=-1e18;
int val[mxn+10],need[mxn+10];
int32_t main(){
fastio
int n;cin>>n;
int nsum=0,sum=0;
for(int i=0;i<n;i++){
cin>>val[i]>>need[i];
sum+=val[i];
nsum+=need[i];
}
bool yes=false,b=false;
if(nsum==0){
if(sum)cout<<"No";
else cout<<"Yes";
return 0;
}
while(sum>=nsum){
yes=true;
b=true;
for(int i=0;i<n;i++){
if(val[i]<=need[i])continue;
int k=ceil(1.0*(val[i]-need[i])/2);
sum-=k;
val[(i+1)%n]+=k;
val[i]-=k*2;
b=false;
}
if(b)break;
}
yes=true;
for(int i=0;i<n;i++)if(val[i]!=need[i])yes=false;
if(yes)cout<<"Yes";
else cout<<"No";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
0 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
0 ms |
2396 KB |
Output is correct |
29 |
Correct |
0 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
0 ms |
2396 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
0 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
0 ms |
2396 KB |
Output is correct |
29 |
Correct |
0 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
0 ms |
2396 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2648 KB |
Output is correct |
34 |
Correct |
0 ms |
2396 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2392 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
0 ms |
2396 KB |
Output is correct |
40 |
Correct |
1 ms |
2648 KB |
Output is correct |
41 |
Correct |
1 ms |
2396 KB |
Output is correct |
42 |
Correct |
0 ms |
2396 KB |
Output is correct |
43 |
Correct |
0 ms |
2396 KB |
Output is correct |
44 |
Correct |
1 ms |
2396 KB |
Output is correct |
45 |
Correct |
0 ms |
2396 KB |
Output is correct |
46 |
Correct |
1 ms |
2392 KB |
Output is correct |
47 |
Correct |
1 ms |
2392 KB |
Output is correct |
48 |
Correct |
1 ms |
2396 KB |
Output is correct |
49 |
Correct |
1 ms |
2396 KB |
Output is correct |
50 |
Correct |
1 ms |
2396 KB |
Output is correct |
51 |
Correct |
1 ms |
2396 KB |
Output is correct |
52 |
Correct |
1 ms |
2396 KB |
Output is correct |
53 |
Correct |
0 ms |
2396 KB |
Output is correct |
54 |
Correct |
1 ms |
2396 KB |
Output is correct |
55 |
Correct |
1 ms |
2396 KB |
Output is correct |
56 |
Correct |
1 ms |
2396 KB |
Output is correct |
57 |
Correct |
0 ms |
2396 KB |
Output is correct |
58 |
Correct |
1 ms |
2396 KB |
Output is correct |
59 |
Correct |
1 ms |
2396 KB |
Output is correct |
60 |
Correct |
1 ms |
2396 KB |
Output is correct |
61 |
Correct |
1 ms |
2396 KB |
Output is correct |
62 |
Correct |
1 ms |
2596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
0 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
0 ms |
2396 KB |
Output is correct |
29 |
Correct |
0 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
0 ms |
2396 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2648 KB |
Output is correct |
34 |
Correct |
0 ms |
2396 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2392 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
0 ms |
2396 KB |
Output is correct |
40 |
Correct |
1 ms |
2648 KB |
Output is correct |
41 |
Correct |
1 ms |
2396 KB |
Output is correct |
42 |
Correct |
0 ms |
2396 KB |
Output is correct |
43 |
Correct |
0 ms |
2396 KB |
Output is correct |
44 |
Correct |
1 ms |
2396 KB |
Output is correct |
45 |
Correct |
0 ms |
2396 KB |
Output is correct |
46 |
Correct |
1 ms |
2392 KB |
Output is correct |
47 |
Correct |
1 ms |
2392 KB |
Output is correct |
48 |
Correct |
1 ms |
2396 KB |
Output is correct |
49 |
Correct |
1 ms |
2396 KB |
Output is correct |
50 |
Correct |
1 ms |
2396 KB |
Output is correct |
51 |
Correct |
1 ms |
2396 KB |
Output is correct |
52 |
Correct |
1 ms |
2396 KB |
Output is correct |
53 |
Correct |
0 ms |
2396 KB |
Output is correct |
54 |
Correct |
1 ms |
2396 KB |
Output is correct |
55 |
Correct |
1 ms |
2396 KB |
Output is correct |
56 |
Correct |
1 ms |
2396 KB |
Output is correct |
57 |
Correct |
0 ms |
2396 KB |
Output is correct |
58 |
Correct |
1 ms |
2396 KB |
Output is correct |
59 |
Correct |
1 ms |
2396 KB |
Output is correct |
60 |
Correct |
1 ms |
2396 KB |
Output is correct |
61 |
Correct |
1 ms |
2396 KB |
Output is correct |
62 |
Correct |
1 ms |
2596 KB |
Output is correct |
63 |
Correct |
150 ms |
16008 KB |
Output is correct |
64 |
Correct |
89 ms |
16012 KB |
Output is correct |
65 |
Correct |
159 ms |
16000 KB |
Output is correct |
66 |
Correct |
84 ms |
15956 KB |
Output is correct |
67 |
Correct |
94 ms |
15952 KB |
Output is correct |
68 |
Correct |
100 ms |
16008 KB |
Output is correct |
69 |
Correct |
159 ms |
16004 KB |
Output is correct |
70 |
Correct |
84 ms |
15952 KB |
Output is correct |
71 |
Correct |
94 ms |
15960 KB |
Output is correct |
72 |
Correct |
101 ms |
16008 KB |
Output is correct |
73 |
Correct |
150 ms |
15996 KB |
Output is correct |
74 |
Correct |
84 ms |
15956 KB |
Output is correct |
75 |
Correct |
93 ms |
15916 KB |
Output is correct |
76 |
Correct |
99 ms |
15952 KB |
Output is correct |
77 |
Correct |
157 ms |
16096 KB |
Output is correct |
78 |
Correct |
126 ms |
15952 KB |
Output is correct |
79 |
Correct |
104 ms |
16072 KB |
Output is correct |
80 |
Correct |
116 ms |
16008 KB |
Output is correct |
81 |
Correct |
124 ms |
16012 KB |
Output is correct |
82 |
Correct |
71 ms |
16012 KB |
Output is correct |
83 |
Correct |
71 ms |
15956 KB |
Output is correct |
84 |
Correct |
71 ms |
16012 KB |
Output is correct |
85 |
Correct |
154 ms |
16020 KB |
Output is correct |
86 |
Correct |
164 ms |
16012 KB |
Output is correct |
87 |
Correct |
107 ms |
16024 KB |
Output is correct |
88 |
Correct |
119 ms |
15956 KB |
Output is correct |