#include<bits/stdc++.h>
#define STIZE(x) fprintf(stderr, "STIZE%d\n", x);
#define PRINT(x) fprintf(stderr, "%s = %d\n", #x, x);
#define NL(x) printf("%c", " \n"[(x)]);
#define lld long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mid (l+r)/2
#define endl '\n'
#define all(a) begin(a),end(a)
#define sz(a) int((a).size())
#define LINF 1000000000000000LL
#define INF 1000000000
#define EPS 1e-9
using namespace std;
#define MAXN 2010
lld N, P, Q, A[MAXN];
lld dp[MAXN][MAXN], l1[MAXN], l2[MAXN];
bool check(lld w) {
for(int i = 0; i <= N; i++) {
for(int j = 0; j <= P; j++) dp[i][j] = INF;
}
for(int i = 1; i <= N; i++) {
for(int j = i-1; j >= 0; j--) {
if(A[j] <= A[i]-w && A[j+1] > A[i]-w) l1[i] = j;
if(A[j] <= A[i]-2*w && A[j+1] > A[i]-2*w) l2[i] = j;
}
}
for(int i = 0; i <= P; i++) dp[0][i] = 0;
for(int i = 1; i <= N; i++) {
for(int j = 0; j <= P; j++) {
if(j > 0) dp[i][j] = min(dp[l1[i]][j-1], dp[l2[i]][j]+1);
else dp[i][j] = dp[l2[i]][j]+1;
}
}
for(int i = 0; i <= P; i++) if(dp[N][i] <= Q) return true;
return false;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cerr.tie(0);
cin >> N >> P >> Q;
A[0] = -2000000000;
for(int i = 1; i <= N; i++) cin >> A[i];
sort(A+1, A+1+N);
if(P >= N) cout << 1 << endl;
lld l = 1, r = 1000000000, rez = r;
while(l <= r) {
if(check(mid)) rez = mid, r = mid-1;
else l = mid+1;
}
cout << rez << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
760 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
94 ms |
8496 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
371 ms |
31920 KB |
Output is correct |
4 |
Runtime error |
180 ms |
64508 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Halted |
0 ms |
0 KB |
- |