Submission #748219

#TimeUsernameProblemLanguageResultExecution timeMemory
748219mariowongWatching (JOI13_watching)C++14
100 / 100
283 ms16052 KiB
#include <bits/stdc++.h> using namespace std; int a[2005],dp[2005][2005],large_range[2005],small_range[2005]; int main(){ ios::sync_with_stdio(false); int n,p,q; cin >> n >> p >> q; for (int i=1;i<=n;i++) cin >> a[i]; sort(a+1,a+1+n); int L=1,R=1000000000; while (L < R){ int mid=(L+R)/2; int ptrL=0,ptrS=0; for (int i=1;i<=n;i++){ while (a[i]-a[ptrL+1] >= mid*2) ptrL++; while (a[i]-a[ptrS+1] >= mid) ptrS++; large_range[i]=ptrL; small_range[i]=ptrS; } for (int i=0;i<=n;i++){ for (int j=0;j<=min(n,q);j++){ dp[i][j]=1e9; } } for (int i=0;i<=min(n,q);i++) dp[0][i]=0; for (int i=1;i<=n;i++){ for (int j=0;j<=min(n,q);j++){ dp[i][j]=dp[small_range[i]][j]+1; if (j != 0) dp[i][j]=min(dp[i][j],dp[large_range[i]][j-1]); } } if (dp[n][min(n,q)] <= p) R=mid; else L=mid+1; } cout << L << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...