# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
445248 |
2021-07-17T05:10:45 Z |
erke |
Watching (JOI13_watching) |
C++11 |
|
336 ms |
15372 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
int main() {
cin.tie(0)->sync_with_stdio(0);
int n, p, q;
cin >> n >> p >> q;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
if (n - p - q <= 0) {
cout << 1 << '\n';
return 0;
}
sort(a.begin() + 1, a.end());
auto check = [&](int m) {
vector<vector<int>> dp(n + 1, vector<int>(p + 1, 1e9));
for (int i = 0; i <= p; i++) {
dp[0][i] = 0;
}
int pp = 1, pq = 1;
for (int i = 1; i <= n; i++) {
while (a[i] - a[pp] + 1 > m) pp++;
while (a[i] - a[pq] + 1 > 2 * m) pq++;
dp[i][0] = dp[pq - 1][0] + 1;
for (int j = 1; j <= p; j++) {
dp[i][j] = min(dp[pq - 1][j] + 1, dp[pp - 1][j - 1]);
}
}
return (dp[n][p] <= q);
};
int l = 1, r = 1e9, ans = -1;
while (l <= r) {
int m = (l + r) / 2;
if (check(m)) {
ans = m;
r = m - 1;
}
else l = m + 1;
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
284 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
5 ms |
460 KB |
Output is correct |
8 |
Correct |
23 ms |
1384 KB |
Output is correct |
9 |
Correct |
126 ms |
6380 KB |
Output is correct |
10 |
Correct |
336 ms |
15372 KB |
Output is correct |
11 |
Correct |
18 ms |
1212 KB |
Output is correct |
12 |
Correct |
173 ms |
8228 KB |
Output is correct |
13 |
Correct |
5 ms |
460 KB |
Output is correct |
14 |
Correct |
5 ms |
460 KB |
Output is correct |
15 |
Correct |
5 ms |
448 KB |
Output is correct |