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 <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <random>
#include <ctime>
#include <utility>
#include <fstream>
#include <queue>
#include <deque>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("vpt")
#pragma GCC optimize("unroll-loops")
#pragma comment(linker, "/STACK:256000000")
#pragma warning(disable:4996)
using namespace std;
typedef long long ll;
typedef long double ld;
const ld pi = 3.14159265358979323846264;
const char el = '\n';
//const int inf = 1000'000'000;
const ll llinf = 1e18, mod = 1000'000'007;
#define forn(i, n) for (int i = 0; i < (int)n; ++i)
#define firn(i, n) for (int i = 1; i < (int)n; ++i)
#define all(v) v.begin(), v.end()
#define x first
#define y second
template<typename T> bool uin(T &a, T b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T> bool uax(T &a, T b) { if (b > a) { a = b; return 1; } return 0; }
template<class iterator> void output(iterator begin, iterator end, char p = ' ', ostream &out = cout) { while (begin != end) { out << (*begin) << p; begin++; } out << el; }
template<class T> void output(T x, char p = ' ', ostream &out = cout) { output(all(x), p, out); }
mt19937 rnd(time(NULL));
#define int long long
const int N = 1000 * 1000 + 228;
int n;
int a[N], b[N];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i] >> b[i];
}
bool change = 1;
while (change) {
change = 0;
for (int i = 1; i <= n; ++i) {
if (a[i] >= 2 && a[i] > b[i]) {
int x = max(1LL, (a[i] - b[i]) / 2);
if (!x) continue;
a[i] -= 2 * x;
a[i % n + 1] += x;
change = 1;
}
}
}
for (int i = 1; i <= n; ++i) {
if (a[i] != b[i]) {
cout << "No\n";
return 0;
}
}
cout << "Yes\n";
return 0;
}
/*
<>>><<><<<<<>>><
0 3 2 1 0 1 2 0 1 2 3 4 5 2 1 0 1
0 3 2 1 0 1 2 0 1 2 3 4 5 3 2 0 1
*/
Compilation message (stderr)
remittance.cpp:24:0: warning: ignoring #pragma comment [-Wunknown-pragmas]
#pragma comment(linker, "/STACK:256000000")
remittance.cpp:25:0: warning: ignoring #pragma warning [-Wunknown-pragmas]
#pragma warning(disable:4996)
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |