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>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++)
#define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--)
typedef pair<ll, ll> pi;
#define f first
#define s second
typedef vector<ll> vi;
typedef vector<pi> vpi;
#define pb push_back
#define all(v) v.begin(), v.end()
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll n, a[1000005], b[1000005], arr[1000005];
bool az = 1, bz = 1;
int main() {
fastio; cin >> n;
FOR(i, 0, n-1) {
cin >> a[i] >> b[i];
if (a[i] != 0) az = 0;
if (b[i] != 0) bz = 0;
}
if (bz) cout << (az ? "Yes" : "No");
else {
while (true) {
bool ok = false;
FOR(i, 0, n-1) if (a[i] > b[i]) {
ll send = (a[i] - b[i] + 1)/2; //ceiling!!
a[(i+1)%n] += send;
a[i] -= 2*send;
ok = true;
}
if (!ok) break;
}
bool ok = 1;
FOR(i, 0, n-1) if (a[i] != b[i]) ok = 0;
cout << (ok ? "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... |