#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
//#define int long long
#define sz(a) (int)a.size()
const int mxN = (int)2e3+10;
const int LINF = (int)1e9;
int n, p, q;
vector<int> v;
int a[mxN], ip[mxN], iq[mxN], dp[mxN][mxN];
bool work(int w){
v.clear(); v.pb(0);
for(int i = 1, s=0; i <= n; i++){
s+=a[i]-a[i-1]; v.pb(s);
for(int j = 1; j < sz(v); j++){
if(s-v[j]+1 <=w){ ip[i]=j-1; break; }
}
}
v.clear(); v.pb(0);
for(int i = 1, s=0; i <= n; i++){
s+=a[i]-a[i-1]; v.pb(s);
for(int j = 1; j < sz(v); j++){
if(s-v[j]+1 <=2*w){ iq[i]=j-1; break; }
}
}
ip[1]=iq[1]=0;
for(int i = 0; i <= n; i++)
for(int j = 0; j <= q; j++)
dp[i][j]=LINF;
dp[0][0]=0;
for(int i = 1; i <= n; i++){
for(int j = 0; j <= q; j++){
dp[i][j] = min(dp[i][j], dp[ip[i]][j]+1);
if(j) dp[i][j] = min(dp[i][j], dp[iq[i]][j-1]);
}
}
for(int i = 0; i <= q; i++)
if(dp[n][i]<=p) return true;
return false;
}
int32_t main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> p >> q;
for(int i = 1; i <= n; i++) cin >> a[i];
sort(a+1,a+n+1);
if(p+q>=n){cout<<1;return 0;}
int l = 1, r = (int)1e9;
while(l<r){
int mid = (l+r)/2;
if(work(mid)) r=mid;
else l=mid+1;
}
cout << l;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
716 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
11 |
Correct |
1 ms |
712 KB |
Output is correct |
12 |
Correct |
1 ms |
724 KB |
Output is correct |
13 |
Correct |
1 ms |
724 KB |
Output is correct |
14 |
Correct |
1 ms |
724 KB |
Output is correct |
15 |
Correct |
1 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
8400 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
360 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
54 ms |
8404 KB |
Output is correct |
8 |
Correct |
187 ms |
14264 KB |
Output is correct |
9 |
Correct |
83 ms |
9360 KB |
Output is correct |
10 |
Correct |
76 ms |
9080 KB |
Output is correct |
11 |
Correct |
366 ms |
16112 KB |
Output is correct |
12 |
Correct |
219 ms |
16056 KB |
Output is correct |
13 |
Correct |
50 ms |
8532 KB |
Output is correct |
14 |
Correct |
54 ms |
8484 KB |
Output is correct |
15 |
Correct |
58 ms |
8532 KB |
Output is correct |