Submission #1345917

#TimeUsernameProblemLanguageResultExecution timeMemory
1345917thaibaotran555Watching (JOI13_watching)C++20
0 / 100
1 ms344 KiB
///TRAN THAI BAO :3

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

#define maxN 100007
int n, p, q;
vector<long long>a;

bool check(int w)
{
    int pL = p, qL = q;
    int i = 0;
    while(i < n)
    {
        if(pL == 0 && qL == 0)
            return false;
        long long nexPos = -1;
        if(qL > 0)
        {
            vector<long long>::iterator it = lower_bound(a.begin(), a.end(), a[i]+w);
            if((it != a.end() && (long long)*it - a[i] + 1 <= 2*w) || pL == 0)
            {
                nexPos = a[i] + 2ll*w;
            }
        }
        if(nexPos != -1)
        {
            qL--;
        }
        else
        {
            nexPos = a[i]+w;
            pL--;
        }
        while(i < n && a[i] < nexPos)
            i++;
    }
    return true;
}

void solve()
{
    cin >> n >> p >> q;
    for(int i = 1; i <= n; i++)
    {
        int x;
        cin >> x;
        a.push_back(x);
    }
    sort(a.begin(), a.end());
    int lo = 1, hi = 1000000000, mid, ans = 1000000000;
    while(lo <= hi)
    {
        mid = (lo+hi)/2;
        if(check(mid))
        {
            ans = min(ans, mid);
            hi = mid-1;
        }
        else lo = mid+1;
    }
    cout << ans;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...