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>
using namespace std;
int main()
{
int a; cin >> a;
pair<int, int> arr[a + 50];
for(int i=0; i < a; i ++)
cin >> arr[i].first >> arr[i].second;
while(true)
{
bool yes = false;
for(int i=0; i < a; i ++)
{
if(arr[i].first < arr[i].second + 2) continue;
int t = arr[i].first - arr[i].second;
arr[i].first -= t * 2;
if(i == a - 1) arr[0].first += t;
else arr[i + 1].first += t;
yes = true;
}
if(!yes) break;
}
bool yes1 = true, yes2 = true;
for(int i=0; i < a; i ++)
{
if(arr[i].first != arr[i].second) yes1 = false;
if(arr[i].first != arr[i].second + 1 || arr[i].first < 2) yes2 = false;
}
if(yes1 || yes2) cout << "Yes";
else cout << "No";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |