# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
200525 | HellAngel | Remittance (JOI19_remittance) | C++14 | 31 ms | 16380 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 int long long
using namespace std;
const int maxn = 1000007;
int a[maxn], b[maxn], n;
struct cmp
{
bool operator()(const pair<int, int> &a, const pair<int, int> &b)
{
if(a.first == b.first) return ::a[a.second] < ::a[b.second];
return a.first < b.first;
}
};
void AnsNo()
{
cout << "No";
exit(0);
}
void AnsYes()
{
cout << "Yes";
exit(0);
}
void Change(int pos, int val)
{
a[pos] -= 2 * val;
pos++;
if(pos == n) pos = 0;
a[pos] += val;
}
int32_t main()
{
auto start = chrono::steady_clock::now();
ios_base::sync_with_stdio(0);
cin.tie(0);
if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin);
cin >> n;
for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
while(true)
{
bool ok = false;
for(int i = 0; i < n; i++)
{
if(a[i] > b[i])
{
int nxt = a[i] - b[i] >> 1;
if(nxt == 0 && a[i] > 1) Change(a[i], 1), ok = 1;
if(nxt > 0) Change(a[i], nxt), ok = 1;
}
}
if(!ok) break;
}
for(int i = 0; i < n; i++) if(a[i] != b[i]) AnsNo();
AnsYes();
auto finish = chrono::steady_clock::now();
cerr << '\n'<< chrono::duration_cast<chrono::milliseconds>(finish - start).count();
}
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... |