# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
240040 | nafis_shifat | Watching (JOI13_watching) | C++14 | 123 ms | 15232 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mxn=2001;
int p,q,n;
int a[mxn];
bool check(int w) {
int dp[n+1][p+1];
for(int i=0;i<=p;i++)dp[0][i]=0;
int cur=1;
int pt1=1,pt2=1;
for(int i=1;i<=n;i++) {
while(a[i]-a[pt1]>=w)pt1++;
while(a[i]-a[pt2]>=2*w)pt2++;
dp[i][0]=dp[pt2-1][0]+1;
for(int j=1;j<=p;j++) {
dp[i][j]=min(dp[pt1-1][j-1],dp[pt2-1][j]+1);
}
}
return dp[n][p]<=q;
}
int main() {
cin>>n>>p>>q;
if(p+q>=n) {
cout<<1<<endl;
return 0;
}
for(int i=1;i<=n;i++)cin>>a[i];
sort(a+1,a+n+1);
int lo=1;
int hi=1e9;
int ans;
while(lo<=hi) {
int mid=lo+hi>>1;
if(check(mid)) {
ans=mid;
hi=mid-1;
} else {
lo=mid+1;
}
}
cout<<ans<<endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |