# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
136652 | junodeveloper | Watching (JOI13_watching) | C++14 | 346 ms | 16248 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 sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int n, P, Q, a[2010], trans[2010][2], dp[2010][2010];
bool f(int w) {
int i,j=1,k=1;
for(i=1;i<=n;i++) {
while(j<=n&&a[j]<a[i]+w)j++;
while(k<=n&&a[k]<a[i]+2*w)k++;
trans[i][0]=j,trans[i][1]=k;
}
int res=1e9;
for(i=n;i>=1;i--) {
for(j=0;j<=Q;j++) {
dp[i][j]=1e9;
dp[i][j]=min(dp[i][j], dp[trans[i][0]][j]+1);
if(j>0) dp[i][j]=min(dp[i][j], dp[trans[i][1]][j-1]);
if(i==1)res=min(res,dp[i][j]);
}
}
return res<=P;
}
int main() {
scanf("%d%d%d",&n,&P,&Q);
P=min(P,n), Q=min(Q,n);
int i;
for(i=1;i<=n;i++)scanf("%d",a+i);
sort(a+1,a+n+1);
int lo=0,hi=1e9;
while(lo<hi) {
int mid=(lo+hi)/2;
if(f(mid)) hi=mid;
else lo=mid+1;
}
printf("%d", lo);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |