# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
373358 | BartolM | Watching (JOI13_watching) | C++17 | 132 ms | 16256 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;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;
const int INF=0x3f3f3f3f;
const int N=2005;
int n, A, B;
ll p[N];
int dp[N][N];
int nx_w[N], nx_2w[N];
int rek(int pos, int kol) {
if (kol>A) return INF;
if (pos>=n) return 0;
int &ret=dp[pos][kol];
if (ret!=-1) return ret;
ret=rek(nx_w[pos], kol+1);
ret=min(ret, rek(nx_2w[pos], kol)+1);
return ret;
}
int check(ll w) {
for (int i=0; i<n; ++i) {
nx_w[i]=nx_2w[i]=i+1;
for (int j=i+1; j<n; ++j) {
if (p[j]-p[i]<w) nx_w[i]=j+1;
if (p[j]-p[i]<w*2) nx_2w[i]=j+1;
}
}
memset(dp, -1, sizeof dp);
return rek(0, 0)<=B;
}
void solve() {
sort(p, p+n);
ll lo=0, hi=1e9+3, mid;
while (lo<hi) {
mid=(lo+hi)/2;
if (check(mid)) hi=mid;
else lo=mid+1;
}
printf("%lld\n", lo);
}
void load() {
scanf("%d %d %d", &n, &A, &B);
for (int i=0; i<n; ++i) scanf("%lld", p+i);
}
int main() {
load();
solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |