#include<bits/stdc++.h>
#pragma GCC optimize("-Ofast")
#pragma GCC optimize("trapv")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")
#define I inline void
#define S struct
#define vi vector<int>
#define vii vector<pair<int,int>>
#define pii pair<int,int>
#define pll pair<ll,ll>
using namespace std ;
using ll = long long ;
using ld = long double ;
const int N = 1e6 + 7 , mod = 1e9 + 7 ;
const ll inf = 2e18 ;
// How interesting!
int n ;
vector<int> a(N , 0) , b(N , 0) ;
int main(){
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
//freopen("in.in" , "r" , stdin) ;
cin >> n;
for(int i = 0 ; i < n ; ++ i){
cin >> a[i] >> b[i] ;
}
for(int k = 0 ; k < 100 ; ++ k){
for(int i = 0 ;i < n ; ++ i){
if(a[i] > b[i] && a[i] > 1){
int c = (a[i] - b[i]) >> 1 ;
if(c * 2 > a[i]) c-- ;
a[i] -= c * 2 ;
a[(i+1)%n]+=c ;
}
}
if(a == b)
return cout<<"Yes" , 0 ;
}
cout<<"No" ;
return 0 ;
}
/*
- bounds sir (segtree = 4N, eulerTour = 2N, ...)
- a variable defined twice?
- will overflow?
- is it a good complexity?
- don't mess up indices (0-indexed vs 1-indexed)
- reset everything between testcases.
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8192 KB |
Output is correct |
2 |
Correct |
6 ms |
8192 KB |
Output is correct |
3 |
Correct |
6 ms |
8192 KB |
Output is correct |
4 |
Correct |
8 ms |
8192 KB |
Output is correct |
5 |
Correct |
6 ms |
8192 KB |
Output is correct |
6 |
Correct |
6 ms |
8192 KB |
Output is correct |
7 |
Correct |
6 ms |
8192 KB |
Output is correct |
8 |
Incorrect |
6 ms |
8192 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8192 KB |
Output is correct |
2 |
Correct |
6 ms |
8192 KB |
Output is correct |
3 |
Correct |
6 ms |
8192 KB |
Output is correct |
4 |
Correct |
8 ms |
8192 KB |
Output is correct |
5 |
Correct |
6 ms |
8192 KB |
Output is correct |
6 |
Correct |
6 ms |
8192 KB |
Output is correct |
7 |
Correct |
6 ms |
8192 KB |
Output is correct |
8 |
Incorrect |
6 ms |
8192 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8192 KB |
Output is correct |
2 |
Correct |
6 ms |
8192 KB |
Output is correct |
3 |
Correct |
6 ms |
8192 KB |
Output is correct |
4 |
Correct |
8 ms |
8192 KB |
Output is correct |
5 |
Correct |
6 ms |
8192 KB |
Output is correct |
6 |
Correct |
6 ms |
8192 KB |
Output is correct |
7 |
Correct |
6 ms |
8192 KB |
Output is correct |
8 |
Incorrect |
6 ms |
8192 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |