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;
#define int long long
#define ll long long
#define pii pair<int, int>
#define ff first
#define ss second
#define pb push_back
#define rep(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define rep1(i, a, b) for (int i = (int)a; i >= (int)b; --i)
#define all(x) x.begin(), x.end()
#define sp(x) setprecision(x) << fixed
typedef long double db;
const int N = 1e6 + 5;
const int inf = 1e9;
bool solve() {
int n; cin >> n;
vector<int> a(n + 1), b(n + 1);
rep(i, 1, n) cin >> a[i] >> b[i];
bool change = 1;
while (change) {
change = 0;
// rep(i, 1, n) cout << a[i] << ' ' << b[i] << '\n';
// cout << '\n';
rep(i, 1, n) {
int nx = (i == n) ? 1 : i + 1;
int add = (a[i] - b[i]) / 2;
if (add > 0) {
// cout<<"i,add="<<i<<' '<<add<<'\n';
a[nx] += add;
a[i] -= 2 * add;
change = 1;
}
}
}
rep(i, 1, n) if (a[i] != b[i]) return false;
return true;
}
main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cout << (solve() ? "Yes" : "No");
}
Compilation message (stderr)
remittance.cpp:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
45 | 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... |