Submission #723731

#TimeUsernameProblemLanguageResultExecution timeMemory
723731fdnfksdWatching (JOI13_watching)C++14
100 / 100
231 ms31788 KiB
#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=2e5;
const ll inf=1e18;
const ll mod=1e9+7;
ll n,q,dp[2002][2002],a[maxN],p;
ll check(ll mid)
{
    ll k=1;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=q;j++) dp[i][j]=inf;
    }
    dp[0][0]=0;
    ll e=1;
    for(int i=1;i<=n;i++)
    {
        while(k<=n&&a[i]-a[k]+1>2*mid) k++;
        while(e<=n&&a[i]-a[e]+1>mid) e++;
        for(int j=0;j<=min(1ll*i,q);j++)
        {
            dp[i][j]=dp[e-1][j]+1;
            if(j>0)
            {
                dp[i][j]=min(dp[i][j],dp[k-1][j-1]);
            }
        }
    }
    for(int i=0;i<=q;i++)
    {
        if(dp[n][i]<=p) return true;
    }
    return false;
}
void solve()
{
    cin >> n >> p >> q;
    q=min(q,n);
    for(int i=1;i<=n;i++) cin >> a[i];
    sort(a+1,a+n+1);
    ll low=1,high=1e9;
    while(low<=high)
    {
        ll mid=low+high>>1;
        if(check(mid)) high=mid-1;
        else low=mid+1;
    }
    cout << low;
}
int main()
{
    fastio
    //freopen(TASKNAME".INP","r",stdin);
    //freopen(TASKNAME".OUT","w",stdout);
    solve();
}

Compilation message (stderr)

watching.cpp: In function 'void solve()':
watching.cpp:51:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   51 |         ll mid=low+high>>1;
      |                ~~~^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...