# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1210969 | nguyn | Remittance (JOI19_remittance) | C++20 | 118 ms | 8264 KiB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define pii pair<int,int>
const int N = 1e6 + 5;
int n;
int a[N];
int b[N];
signed main(){
ios_base::sync_with_stdio(false) ;
cin.tie(0) ; cout.tie(0) ;
if (fopen("INP.INP" ,"r")) {
freopen("INP.INP" ,"r" , stdin) ;
freopen("OUT.OUT" , "w" , stdout) ;
}
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
}
while(1) {
bool ok = 0;
for (int i = 1; i <= n; i++) {
int nxt = i + 1;
if (nxt > n) nxt = 1;
if ((a[i] - b[i]) >= 2) {
int t = (a[i] - b[i]) / 2;
a[i] -= 2 * t;
a[nxt] += t;
ok = 1;
}
}
// for (int i = 1; i <= n; i++) {
// cout << a[i] << ' ';
// }
// cout << '\n';
if (!ok) break;
}
while(1) {
bool ok = 0;
for (int i = 1; i <= n; i++) {
int nxt = i + 1;
if (nxt > n) nxt = 1;
if (a[i] > b[i] && a[i] > 1) {
a[i] -= 2;
a[nxt]++;
ok = 1;
}
}
if (!ok) break;
}
bool ok = 1;
for (int i = 1; i <= n; i++) {
if (a[i] != b[i]) {
ok = 0;
break;
}
}
cout << (ok ? "Yes" : "No");
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |