#include<bits/stdc++.h>
using namespace std;
const int N = 2005;
int v[N];
int dp[N][N];
int n, p, q;
bool check(int w){
int lst, lst2;
for(int i =0 ; i<N; i++){
for(int j = 0; j < N; j++){
dp[i][j] = INT_MAX;
dp[0][j] = 0;
}
}
lst = lst2 = 0;
for(int i =1 ; i<=n; i++){
while(lst < i && v[i] - v[lst + 1] + 1 > w)
lst++;
while(lst2 < i && v[i] - v[lst2 + 1] + 1 > 2*w)
lst2++;
for(int j = 0; j <= i; j++ ){
if(dp[lst][j] != INT_MAX)
dp[i][j] = min(dp[i][j], dp[lst][j] + 1);
if(j)
dp[i][j] = min(dp[i][j], dp[lst2][j-1]);
}
}
for(int i = 0; i <=q; i++){
if(dp[n][i] <=p)
return true;
}
return false;
}
int main()
{
//freopen(".in","r",stdin);
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>n>>p>>q;
for(int i =1 ; i<=n; i++){
cin>>v[i];
}
sort(v+1, v+n+1);
if(p + q >= n){
cout<<"1";
return 0;
}
int pas = 0;
for(int p2 = 1<<29; p2>0; p2>>=1){
if(check(pas + p2) == false)
pas+=p2;
}
cout<<pas + 1;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
123 ms |
15948 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
127 ms |
15948 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
122 ms |
16036 KB |
Output is correct |
8 |
Correct |
133 ms |
16032 KB |
Output is correct |
9 |
Correct |
121 ms |
15932 KB |
Output is correct |
10 |
Correct |
124 ms |
16048 KB |
Output is correct |
11 |
Correct |
126 ms |
16032 KB |
Output is correct |
12 |
Correct |
122 ms |
15928 KB |
Output is correct |
13 |
Correct |
122 ms |
16044 KB |
Output is correct |
14 |
Correct |
128 ms |
16036 KB |
Output is correct |
15 |
Correct |
123 ms |
15948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
256 ms |
15948 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
236 ms |
16052 KB |
Output is correct |
8 |
Correct |
248 ms |
16052 KB |
Output is correct |
9 |
Correct |
265 ms |
16148 KB |
Output is correct |
10 |
Correct |
254 ms |
15948 KB |
Output is correct |
11 |
Correct |
260 ms |
16068 KB |
Output is correct |
12 |
Correct |
253 ms |
16052 KB |
Output is correct |
13 |
Correct |
240 ms |
16048 KB |
Output is correct |
14 |
Correct |
240 ms |
16052 KB |
Output is correct |
15 |
Correct |
253 ms |
16068 KB |
Output is correct |