#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) cerr << #x << " " << x << "\n"
#define debug_with_space(x) cerr << #x << " " << x << " "
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <ll, pii> piii;
typedef tree <pii, null_type, less <pii>, rb_tree_tag, tree_order_statistics_node_update> OST;
const ll NMAX = 2001;
const ll INF = (1LL << 60);
const ll MOD = 1000000007;
const ll BLOCK = 101;
const ll nr_of_bits = 35;
int n, p, q, pp, qq;
int v[NMAX];
int next2w[NMAX];
int nextw[NMAX];
int dp[2001][2001];
bool OK(int w) {
for(int i = 0; i <= p; i++) {
for(int j = 0; j <= q; j++) {
dp[i][j] = 0;
}
}
int r = 0, r1 = 0;
for(int i = 1; i <= n; i++) {
while(r < n && v[r + 1] < v[i] + w)
r++;
nextw[i] = r;
while(r1 < n && v[r1 + 1] < v[i] + 2 * w)
r1++;
next2w[i] = r1;
}
for(int i = 0; i <= p; i++) {
for(int j = 0; j <= q; j++) {
if(i != 0) {
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
int unde = dp[i - 1][j];
unde++;
int r = nextw[unde];
dp[i][j] = max(dp[i][j], dp[i - 1][j] + (r - unde + 1));
}
if(j != 0) {
int unde = dp[i][j - 1];
dp[i][j] = max(dp[i][j], dp[i][j - 1]);
unde++;
int r = next2w[unde];
dp[i][j] = max(dp[i][j], dp[i][j - 1] + (r - unde + 1));
}
}
}
return (dp[p][q] >= n);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int i;
cin >> n >> p >> q;
pp = p;
qq = q;
for(i = 1; i <= n; i++) {
cin >> v[i];
}
sort(v + 1, v + n + 1);
p = min(p, n);
q = min(q, max(0, n - p));
int r = 0, pas = (1 << 29);
while(pas) {
if(!OK(r + pas))
r += pas;
pas /= 2;
}
cout << r + 1;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
748 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
748 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
656 KB |
Output is correct |
12 |
Correct |
1 ms |
620 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
208 ms |
9472 KB |
Output is correct |
4 |
Correct |
9 ms |
8428 KB |
Output is correct |
5 |
Correct |
39 ms |
1004 KB |
Output is correct |
6 |
Correct |
8 ms |
8428 KB |
Output is correct |
7 |
Correct |
3 ms |
492 KB |
Output is correct |
8 |
Correct |
26 ms |
1260 KB |
Output is correct |
9 |
Correct |
30 ms |
3820 KB |
Output is correct |
10 |
Correct |
54 ms |
8684 KB |
Output is correct |
11 |
Correct |
43 ms |
1132 KB |
Output is correct |
12 |
Correct |
258 ms |
8044 KB |
Output is correct |
13 |
Correct |
1 ms |
492 KB |
Output is correct |
14 |
Correct |
1 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |