#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 1e6 + 5, INF = 1e10;
int n;
int a[maxn], b[maxn];
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n;
for (int i=0;i<n;i++) cin >> a[i] >> b[i];
if (*max_element(a, a+n) <= 1) {
for (int i=0;i<n;i++) if (a[i]!=b[i]) {
cout << "No\n";
return 0;
}
cout << "Yes\n";
return 0;
}
for (int i=1;i<n;i++) {
int give = max((a[i] - b[i] + 1) / 2, (int)0);
a[i] -= give * 2, a[(i+1)%n] += give;
int take = b[i] - a[i];
// if (take > 0 && (i > 40 || ((int)1<<i) > INF / take)) {cout << "No\n"; return 0;}
a[0] -= take * (1<<i);
a[i] += take;
// if (a[0] < -INF) {cout << "No\n"; return 0;}
}
// if (a[0] > b[0]) {
// if (n > 40) {cout << "No\n"; return 0;}
// int diff = a[0] - b[0];
// int thing = ((int)1 << n);
// if (diff % (thing-1) == 0 && a[0] - diff / (thing-1) * thing >= 0) cout << "Yes\n";
// else cout << "No\n";
// return 0;
// }
while (a[0] > b[0] && a[0] > (1<<n)) {
a[0] -= (1 << n);
a[0]++;
}
if (a[0] == b[0]) cout << "Yes\n";
else 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... |