This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define ll long long
const int nmax = 1e6 + 5, N = 1e5;
const ll oo = 1e9;
const int lg = 31, M = 2, mod = 1e6;
#define pii pair<ll, ll>
#define fi first
#define se second
#define debug(a, n) for(int i = 1; i <= n; ++i) cout << a[i] << ' '; cout << "\n";
#define endl "\n"
#define task "code"
using namespace std;
int n;
pii a[nmax], b[nmax];
bool check(){
int bs = 40;
while(bs--){
for(int i = 0; i < n; ++i){
if(a[i].fi > a[i].se){
ll x = (a[i].fi - a[i].se) / 2;
a[i].fi -= x * 2;
a[(i + 1) % n].fi += x;
}
}
}
bool ok = 1;
for(int i = 0; i < n;++i){
ok &= (a[i].fi == a[i].se);
}
return ok;
}
main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
// freopen(task".inp", "r", stdin);
// freopen(task".out", "w", stdout);
cin >> n;
for(int i = 0; i < n; ++i) cin >> a[i].fi >> a[i].se;
if(check()) cout << "Yes", exit(0);
int lc = -1, pc = -1;
for(int i = 0; i < n; ++i){
if(a[i].fi > a[i].se){
if(lc == -1) lc = i;
pc = i;
}
b[i] = a[i];
}
if(lc != -1){
ll x = (a[lc].fi - a[lc].se + 1) / 2;
a[lc].fi -= x * 2;
a[(lc + 1) % n].fi += x;
if(check()) cout << "Yes", exit(0);
for(int i = 0; i < n; ++i) a[i] = b[i];
x = (a[pc].fi - a[pc].se + 1) / 2;
a[pc].fi -= x * 2;
a[(pc + 1) % n].fi += x;
if(check()) cout << "Yes", exit(0);
}
cout << "No";
}
/*
*/
Compilation message (stderr)
remittance.cpp:38:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
38 | main(){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |