# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
25399 | khsoo01 | Watching (JOI13_watching) | C++11 | 483 ms | 33472 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>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
ll n, x[2005], a, b, na[2005], nb[2005];
ll dt[2005][2005];
bool can (ll P) {
for(ll i=1;i<=n;i++) {
na[i] = lower_bound(x+1, x+1+n, x[i]+P) - x - 1;
nb[i] = lower_bound(x+1, x+1+n, x[i]+2*P) - x - 1;
for(ll j=0;j<=i;j++) dt[i][j] = inf;
}
for(ll i=1;i<=n;i++) {
for(ll j=0;j<i;j++) {
dt[na[i]][j] = min(dt[na[i]][j], dt[i-1][j] + 1);
dt[nb[i]][j+1] = min(dt[nb[i]][j+1], dt[i-1][j]);
}
}
for(ll i=0;i<=b;i++) if(dt[n][i] <= a) return true;
return false;
}
int main()
{
scanf("%lld%lld%lld",&n,&a,&b);
if(a + b >= n) {puts("1"); return 0;}
for(ll i=1;i<=n;i++) scanf("%lld",&x[i]);
sort(x+1, x+1+n);
ll S = 1, E = inf;
while(S<E) {
ll M = (S+E)/2;
can(M) ? E = M : S = M+1;
}
printf("%lld\n",S);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |