#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;
int a[1<<20][2];
priority_queue<array<int,2>> o,e;
void add(int i)
{
if (a[i][0]>a[i][1]+1)
{
if ((a[i][0]-a[i][1])&1)
o.push({a[i][0]-a[i][1],i});
else
e.push({a[i][0]-a[i][1],i});
}
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int n,x,y;
cin>>n;
for (int i=0;i<n;++i)
{
cin>>a[i][0]>>a[i][1];
add(i);
}
while (!e.empty()||!o.empty())
{
if (!e.empty())
{
x=e.top()[0];
y=e.top()[1];
e.pop();
}
else
{
x=o.top()[0];
y=o.top()[1];
o.pop();
}
if (a[y][0]-a[y][1]!=x)
continue;
//cout<<y<<"\n";
a[(y+1)%n][0]+=x/2;
a[y][0]-=(x/2)*2;
add((y+1)%n);
}
for (int i=0;i<n;++i)
if (a[i][0]!=a[i][1])
{
cout<<"No";
return 0;
}
cout<<"Yes";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |