# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1156160 | nguyn | Watching (JOI13_watching) | C++20 | 662 ms | 16152 KiB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define pii pair<int,int>
const int N = 2e3 + 5;
const int inf = 2e9;
int n, a[N], p, q;
int f[N][N];
signed main(){
ios_base::sync_with_stdio(false) ;
cin.tie(0) ; cout.tie(0) ;
if (fopen("INP.INP" ,"r")) {
freopen("INP.INP" ,"r" , stdin) ;
freopen("OUT.OUT" , "w" , stdout) ;
}
cin >> n >> p >> q;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a + 1, a + 1 + n);
q = min(q, n);
int l = 1;
int r = 1e9;
int res = inf;
while(l <= r) {
int mid = (l + r) / 2;
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= q; j++) {
f[i][j] = -inf;
}
}
f[0][q] = p;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= q; j++) {
if (f[i][j] == -inf) {
continue;
}
if (j) {
int nxt = upper_bound(a + 1, a + 1 + n, a[i + 1] + 2 * mid - 1) - a - 1;
f[nxt][j - 1] = max(f[nxt][j - 1], f[i][j]);
}
int nxt = upper_bound(a + 1, a + 1 + n, a[i + 1] + mid - 1) - a - 1;
f[nxt][j] = max(f[nxt][j], f[i][j] - 1);
}
}
bool ok = 0;
for (int i = 0; i <= q; i++) {
if (f[n][i] >= 0) ok = 1;
}
if (ok) {
res = mid;
r = mid - 1;
}
else {
l = mid + 1;
}
}
cout << res;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |