# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
147191 | Alexa2001 | Remittance (JOI19_remittance) | C++17 | 334 ms | 36428 KiB |
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>
#define yes { cout << "Yes\n"; exit(0); }
#define no { cout << "No\n"; exit(0); }
using namespace std;
const int Nmax = 1e6 + 5;
typedef long long ll;
int n;
ll a[Nmax], b[Nmax];
int main()
{
// freopen("rem.in", "r", stdin);
cin.tie(0); cin.sync_with_stdio(false);
int i, j;
ll s1 = 0, s2 = 0;
cin >> n;
for(i=1; i<=n; ++i) cin >> a[i] >> b[i], s1 += a[i], s2 += b[i];
while(s1 > s2)
{
int i; s1 = 0;
bool modif = 0;
for(i=1; i<=n; ++i)
{
if(a[i] <= b[i]) continue;
int nxt = (i<n ? i+1 : 1);
ll add = (a[i] - b[i] + 1) / 2;
if(a[i] < 2 * add) --add;
a[i] -= 2 * add;
a[nxt] += add;
modif |= (add > 0);
}
if(!modif) break;
for(i=1; i<=n; ++i) s1 += a[i]; //, cerr << a[i] << ' ';
// cerr << '\n';
}
for(i=1; i<=n; ++i)
if(a[i] != b[i]) no
yes
return 0;
}
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... |