This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define s second
#define f first
#define pb push_back
using namespace std;
const int N = 2e3 + 3,inf = 1e9;
int a[N],dp[N][N],n,p,q,arr[N];
int find(int i){
int l = 1,r = n,res = 0;
while (l <= r){
int mid = (l + r)/2;
if (a[mid] < i){
res = mid;
l = mid + 1;
}else{
r = mid - 1;
}
}
return res;
}
bool check(int w){
for (int i = 0; i <= n; i++)
for (int j = 0; j <= p; j++)
dp[i][j] = inf;
dp[0][0] = 0;
for (int i = 1; i <= n; i++){
int l1 = find(a[i] - w + 1);
int l2 = find(a[i] - 2*w + 1);
for (int j = 0; j <= p; j++){
//davsvat patara
dp[i][j + 1] = min(dp[i][j + 1],dp[l1][j]);
//davsvat didi
dp[i][j] = min(dp[i][j],dp[l2][j] + 1);
}
}
for (int i = 0; i <= p; i++)
if (dp[n][i] <= q) return 1;
return 0;
}
signed main() {
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
cin >> n >> p >> q;
for (int i = 1; i <= n; i++)
cin >> arr[i];
sort(arr+1,arr+n+1);
int m = 0;
for (int i = 1; i <= n; i++){
if (i == n || arr[i] != arr[i + 1]) {
a[++m] = arr[i];
}
}
n = m;
p = min(p,n);
q = min(q,n);
int l = 0,r = 1e9,res=-1;
while (l <= r){
int w = (l + r) >> 1;
if (check(w)) {
res = w;
r = w - 1;
}else{
l = w + 1;
}
}
cout<<res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |