#include<bits/stdc++.h>
using namespace std;
#define task "a"
#define ll long long
#define fi first
#define se second
#define ii pair<int, int>
const long mxN = 1e6 + 7, inf = 1e9;
int n;
ll dif[mxN];
ii a[mxN];
bool ret(int j)
{
if (dif[j] >= 0)
return 0;
if (dif[j] < -inf * 2)
return 1;
int bf = j - 1;
if (!bf)
bf = n;
dif[bf] += 2 * dif[j];
dif[j] = 0;
return ret(bf);
}
bool Binary(int mid)
{
for (int i = 1; i <= n; i++)
dif[i] = a[i].fi - a[i].se - mid;
for (int i = 1; i <= n; i++)
{
if (ret(i))
return 0;
}
for (int i = 1; i <= n; i++)
{
if (dif[i])
return 1;
}
cout << "Yes";
exit(0);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//freopen(task".INP", "r", stdin);
//freopen(task".OUT", "w", stdout);
cin >> n;
bool tt = 0;
for (int i = 1; i <= n; i++)
{
cin >> a[i].fi >> a[i].se;
tt |= a[i].se;
}
int l = 0, r = inf * tt;
while (l <= r)
{
int mid = (l + r) / 2;
if (Binary(mid))
l = mid + 1;
else
r = mid - 1;
}
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... |