#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
const int NMAX = 2e5 + 1;
int a[NMAX];
bool slv(int w, int n, int p, int q){
int dp[n + 1][n + 1];
for(int i = 0; i <= n; i++){
for(int j = 0; j <= n; j++){
i == 0 ? dp[i][j] = 0 : dp[i][j] = q + 1;
}
}
int ind1, ind2;
ind1 = ind2 = 0;
for(int i = 1; i <= n; i++){
while(a[i] - a[ind1] >= w) ind1++;
while(a[i] - a[ind2] >= 2 * w) ind2++;
for(int j = 0; j <= n; j++){
dp[i][j] = dp[ind2 - 1][j] + 1;
if(j) dp[i][j] = min(dp[i][j], dp[ind1 - 1][j - 1]);
}
}
return dp[n][p] <= q;
}
int main(){
int n; cin >> n;
int p, q; cin >> p >> q;
for(int i = 1; i <= n; i++) cin >> a[i];
a[0] = -1e9;
sort(a + 1, a + 1 + n);
if(p + q >= n){
cout << 1 << "\n";
return 0;
}
int l = 0, r = 1e9 + 5;
while(l + 1 < r){
int mid = (l + r) / 2;
if(slv(mid, n, p, q)) r= mid;
else l = mid;
}
cout << r;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
312 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
198 ms |
15956 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
223 ms |
15980 KB |
Output is correct |
8 |
Correct |
195 ms |
15980 KB |
Output is correct |
9 |
Correct |
198 ms |
15980 KB |
Output is correct |
10 |
Correct |
196 ms |
15956 KB |
Output is correct |
11 |
Correct |
219 ms |
15988 KB |
Output is correct |
12 |
Correct |
201 ms |
15956 KB |
Output is correct |
13 |
Correct |
193 ms |
15988 KB |
Output is correct |
14 |
Correct |
200 ms |
15984 KB |
Output is correct |
15 |
Correct |
244 ms |
15992 KB |
Output is correct |