#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int N = 2010;
int n, p, q, a[N], dp[N][N], w;
int f(int pos, int tot) {
if(pos == n) return 0;
int &ret = dp[pos][p];
if(~ret) return ret;
ret = 1e9;
int x = lower_bound(a + pos, a + n, a[pos] + w) - a;
int y = lower_bound(a + pos, a + n, a[pos] + w + w) - a;
if(tot < p) ret = f(x, tot + 1);
return ret = min(ret, 1 + f(y, tot));
}
int main(int argc, char const *argv[]) {
scanf("%d %d %d", &n, &p, &q);
for(int i = 0; i < n; i++)
scanf("%d", &a[i]);
p = min(p, n);
sort(a, a + n);
int lo = 1, hi = 1e9, ans = -1;
while(lo <= hi) {
w = lo + hi >> 1;
memset(dp, -1, sizeof dp);
if(f(0, 0) <= q) {
ans = w, hi = w - 1;
} else lo = w + 1;
} printf("%d\n", ans);
}
Compilation message
watching.cpp: In function 'int main(int, const char**)':
watching.cpp:28:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
w = lo + hi >> 1;
~~~^~~~
watching.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &n, &p, &q);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
watching.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &a[i]);
~~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
16248 KB |
Output is correct |
2 |
Correct |
147 ms |
16468 KB |
Output is correct |
3 |
Incorrect |
78 ms |
16468 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
16652 KB |
Output is correct |
2 |
Correct |
97 ms |
16652 KB |
Output is correct |
3 |
Correct |
125 ms |
16792 KB |
Output is correct |
4 |
Correct |
110 ms |
16792 KB |
Output is correct |
5 |
Correct |
112 ms |
16848 KB |
Output is correct |
6 |
Correct |
108 ms |
16896 KB |
Output is correct |
7 |
Incorrect |
139 ms |
16896 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |