#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define dl double long
using namespace std;
const int N = 1e6 + 7;
const int M = 20 + 7;
const ll mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n;
ll a[N];
ll b[N];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
//freopen( "input.txt" , "r" , stdin );
//freopen( "output.txt" , "w" , stdout );
cin >> n;
for( int i = 0; i < n; i++ ){
cin >> a[i] >> b[i];
}
vector < int > used(n , 0);
vector < pair < int , int > > cm;
for( int i = 0; i < n; i++ ){
if( used[i] )break;
if( a[i] >= b[i] ){
int j = (i - 1 + n) % n;
while( a[j] < b[j] ){
used[j] = true;
j = (j - 1 + n) % n;
if( used[j] ){
cout << "No";
return 0;
}
}
int x = (i - 1 + n) % n;
if( x != j )cm.push_back({ x , (j + 1) % n });
}
}
for( int i = 0; i < n; i++ )used[i] = false;
reverse( cm.begin() , cm.end() );
for( int i = 0; i < (int)cm.size(); i++ ){
auto x = cm[i];
ll cost = b[x.fi] - a[x.fi];
cost += cost;
a[x.fi] = b[x.fi];
used[x.fi] = true;
x.fi = (x.fi - 1 + n) % n;
while( a[x.fi] - cost < b[x.fi] ){
cost = b[x.fi] - a[x.fi] + cost;
cost *= 2;
a[x.fi] = b[x.fi];
if( used[x.fi] ){
cout << "No";
return 0;
}
used[x.fi] = 1;
x.fi = (x.fi - 1 + n) % n;
}
a[x.fi] -= cost;
}
for( int j = 0; j < 40; j++ ){
for( int i = 0; i < n; i++ ){
if( a[i] % 2 != b[i] % 2 ){
cout << "No";
return 0;
}
int nx = (i + 1) % n;
a[nx] += (b[i] - a[i]) / 2;
a[i] = b[i];
}
}
cout << "Yes";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Incorrect |
1 ms |
320 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Incorrect |
1 ms |
320 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Incorrect |
1 ms |
320 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |