#include "bits/stdc++.h"
using namespace std;
#define endl "\n"
#define ll long long
#define pb push_back
#define mp make_pair
const long long MOD = 1e9+7;
const long long INF = 1e18;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n;
cin >> n;
vector<ll> a(n, 0), b(n, 0);
for(int i = 0; i<n; i++)
cin >> a[i] >> b[i];
for(int i = 0; i<n-1; i++)
{
if(a[i]>b[i])
{
ll A = a[i], B = b[i];
a[i+1]+=ceil(double(A-B)/2);
a[i]-=2*ceil(double(A-B)/2);
}
}
if(a[n-1]>b[n-1])
{
ll A = a[n-1], B = b[n-1];
a[0]+=ceil(double(A-B)/2);
a[n-1]-=2*ceil(double(A-B)/2);
}
for(int i = 0; i<n-1; i++)
{
if(a[i]>b[i])
{
ll A = a[i], B = b[i];
a[i+1]+=ceil(double(A-B)/2);
a[i]-=2*ceil(double(A-B)/2);
}
}
if(a[n-1]>b[n-1])
{
ll A = a[n-1], B = b[n-1];
a[0]+=ceil(double(A-B)/2);
a[n-1]-=2*ceil(double(A-B)/2);
}
bool flag = true;
for(int i = 0; i<n; i++)
{
if(a[i]!=b[i])
{
flag = false;
break;
}
}
if(flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |