제출 #1263241

#제출 시각아이디문제언어결과실행 시간메모리
1263241tvgk송금 (JOI19_remittance)C++20
0 / 100
0 ms328 KiB
#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)
        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;
    for (int i = 1; i <= n; i++)
        cin >> a[i].fi >> a[i].se;

    int l = 0, r = 1e9;
    while (l <= r)
    {
        int mid = (l + r) / 2;

        if (Binary(mid))
            l = mid + 1;
        else
            r = mid - 1;
    }
    cout << "No";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...