#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define mxn 2005
#define mxm 100005
#define f first
#define s second
#define pb push_back
#define es " "
#define endl '\n'
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define ll long long
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
typedef pair<int, pii> pip;
int n, p, g, pos1[mxn], pos2[mxn], dp[mxn][mxn];
vector<int> v;
int solve(int i, int ss, int b){
if(ss<0 || b<0){
return 0;
}
if(i>=n){
return 1;
}
if(dp[i][b]!=-1){
return dp[i][b];
}
return dp[i][b]=max(solve(pos1[i]+1, ss-1, b), solve(pos2[i]+1, ss, b-1));
}
int main(){
fastio;
cin >> n >> p >> g;
p=min(p, n);
g=min(g, n);
for(int i=1; i<=n; i++){
int x;
cin >> x;
v.pb(x);
}
sort(all(v));
int ini=1, fim=1000000000, meio, resp=1;
while(ini<=fim){
meio=(ini+fim)>>1;
memset(pos1, 0, sizeof(pos1));
memset(pos2, 0, sizeof(pos2));
memset(dp, -1, sizeof(dp));
for(int i=0; i<sz(v); i++){
for(int j=sz(v)-1; j>=i; j--){
if(v[j]-v[i]+1<=2*meio){
if(v[j]-v[i]+1<=meio){
pos1[i]=j;
break;
}else{
pos2[i]=max(pos2[i], j);
}
}
}
}
if(solve(0, p, g)){
resp=meio;
fim=meio-1;
}else{
ini=meio+1;
}
}
cout << resp;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
16040 KB |
Output is correct |
2 |
Correct |
66 ms |
16040 KB |
Output is correct |
3 |
Correct |
67 ms |
16040 KB |
Output is correct |
4 |
Correct |
65 ms |
15948 KB |
Output is correct |
5 |
Incorrect |
68 ms |
15948 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
152 ms |
15948 KB |
Output is correct |
2 |
Correct |
64 ms |
15948 KB |
Output is correct |
3 |
Execution timed out |
1062 ms |
16256 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |