#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
#define f(i,a,b) for(int i = a; i < b; i++)
#define fa(i,a,b) for(int i = a; i >= b; i--)
#define ff first
#define ss second
const int N = 2005;
const ll inf = 1e17 + 100;
int n, p, q, dp[N][N];
int a[N], idw[N], id2w[N];
void go(int w){
queue <pair<int,int>> q1, q2;
f(i,1,n+1){
q1.push({a[i], i}); q2.push({a[i], i});
while(a[i] - q1.front().first > w-1) q1.pop();
idw[i] = q1.front().second;
while(a[i] - q2.front().first > 2*w-1) q2.pop();
id2w[i] = q2.front().second;
}
f(i,1,n+1) f(j,0,n) dp[i][j] = 0;
f(i,1,n+1){
dp[i][0] = dp[id2w[i] - 1][0] + 1;
f(j,1,n){
dp[i][j] = min(dp[idw[i] - 1][j-1], dp[id2w[i] - 1][j] + 1);
}
}
}
int main(){
cin >> n >> p >> q;
set <int> s;
f(i,1,n+1){
int x; cin >> x;
s.insert(x);
}
n = 0;
for(int x: s) a[++n] = x;
int l = 1, r = 1000000000;
while(l < r){
int m = (l+r)>>1;
go(m);
if(p >= n or dp[n][p] <= q) r = m;
else l = m+1;
}
cout << l << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
2 ms |
688 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
696 KB |
Output is correct |
8 |
Correct |
1 ms |
692 KB |
Output is correct |
9 |
Correct |
2 ms |
724 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
11 |
Correct |
1 ms |
724 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 |
193 ms |
16140 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
176 ms |
16064 KB |
Output is correct |
4 |
Correct |
173 ms |
15956 KB |
Output is correct |
5 |
Correct |
210 ms |
16100 KB |
Output is correct |
6 |
Correct |
180 ms |
16188 KB |
Output is correct |
7 |
Correct |
174 ms |
16112 KB |
Output is correct |
8 |
Correct |
170 ms |
16040 KB |
Output is correct |
9 |
Correct |
174 ms |
15956 KB |
Output is correct |
10 |
Correct |
217 ms |
16204 KB |
Output is correct |
11 |
Correct |
172 ms |
16084 KB |
Output is correct |
12 |
Correct |
175 ms |
16112 KB |
Output is correct |
13 |
Correct |
189 ms |
16084 KB |
Output is correct |
14 |
Correct |
174 ms |
16152 KB |
Output is correct |
15 |
Correct |
179 ms |
16128 KB |
Output is correct |