This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*input
2
1 1
2 2
*/
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
int main()
{
clock_t pradzia = clock();
ios_base::sync_with_stdio(false);
int n;
cin >> n;
ll a[n], b[n];
for (int i = 0; i < n; i++)
cin >> a[i] >> b[i];
while ((clock() - pradzia) * 10 <= 9 * CLOCKS_PER_SEC)
{
bool ok = true;
for (int i = n - 1; i >= 0; i--)
{
if (a[i] < b[i])
{
ll c = min(a[(i - 1 + n) % n] / 2, b[i] - a[i]);
a[i] += c;
a[(i - 1 + n) % n] -= 2 * c;
ok = false;
}
}
for (int i = 0; i < n; i++)
{
if (a[i] > b[i])
{
ll c = min(a[i] / 2, (a[i] - b[i] + 1) / 2);
a[i] -= c * 2;
a[(i + 1) % n] += c;
ok = false;
}
}
if (ok)
{
cout << "Yes\n";
return 0;
}
}
cout << "No\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |