This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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];
}
for( int it = 0; it < 35; it++ ){
for( int i = 0; i < n; i++ ){
if( a[i] > b[i] && a[i] > 1 ){
int nx = (i + 1) % n;
ll cost = (a[i] - b[i]) / 2;
cost = max( cost , 1ll );
a[nx] += cost;
a[i] -= cost * 2;
}
}
}
bool f = true;
for( int i = 0; i < n; i++ )f &= (a[i] == b[i]);
cout << (f ? "Yes" : "No");
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |