이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define int long long
const int INF = 1e12;
signed main(void){
// fastio;
int n;
cin>>n;
vector<int> a(n), b(n);
for(int i = 0; i < n; i++){
int x, y;
cin>>x>>y;
a[i] = x - y;
b[i] = y;
}
for(int i = 0; i < n; i++){
if(a[i] < 0){
int nd = - a[i] * 2;
a[i] = 0;
int id = (i - 1 + n) % n;
while(id != i && a[id] < nd && nd < INF){
if(a[id] > 0) nd -= a[id], a[id] = 0;
nd *= 2;
id = (id - 1 + n) % n;
}
if(a[id] < nd){
cout<<"No\n";
return 0;
}
a[id] -= nd;
}
}
int non = 0;
for(int i = 0; ; i = (i + 1) % n){
if(non >= n) break;
if(a[i] <= 0){
non++;
continue;
}
if(a[i] % 2 == 0){
non = 0;
a[(i + 1) % n] += a[i] / 2;
a[i] = 0;
continue;
}
if(b[i] > 0){
non = 0;
a[(i + 1) % n] += (a[i] / 2) + 1;
a[i] = -1;
continue;
}
non++;
}
for(auto x : a){
if(x != 0){
cout<<"No\n";
return 0;
}
}
cout<<"Yes\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... |