Submission #916726

#TimeUsernameProblemLanguageResultExecution timeMemory
916726Dec0DeddWatching (JOI13_watching)C++14
100 / 100
300 ms32192 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2e3+10; const int INF = 1e9+10; ll a[N], n, p, q; ll dp[N][N]; bool check(ll w) { for (int i=0; i<=n; ++i) { for (int j=0; j<=n; ++j) dp[i][j]=INF; } dp[0][0]=0; ll ppt=1, qpt=1; for (int i=1; i<=n; ++i) { while (a[i]-a[ppt]+1 > w) ++ppt; while (a[i]-a[qpt]+1 > 2*w) ++qpt; for (int j=1; j<=p; ++j) dp[i][j]=dp[ppt-1][j-1]; for (int j=0; j<=p; ++j) dp[i][j]=min(dp[i][j], dp[qpt-1][j]+1); } for (int i=0; i<=p; ++i) { if (dp[n][i] <= q) return true; } return false; } void solve() { cin>>n>>p>>q; for (int i=1; i<=n; ++i) cin>>a[i]; sort(a+1, a+n+1); if (p+q >= n) { cout<<1<<"\n"; return; } ll l=1, r=INF, res=INF; while (l <= r) { ll m=(l+r)/2; if (check(m)) res=m, r=m-1; else l=m+1; } cout<<res<<"\n"; } int main() { int t=1; //cin>>t; while (t--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...