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>
using namespace std;
template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl
using ll = long long;
const int inf = 1e9;
const int maxn = 1e5 + 5;
int n,p,q;
int a[maxn];
int dp[2001][2001]; //dp[i][j]: min big cameras for first i events, given we use j small cameras
bool test(int len) {
int l=1;
int r=1;
for (int i=1; i<=n; i++) {
while (a[l] < a[i]-len+1) l++;
while (a[r] < a[i]-2*len+1) r++;
for (int j=0; j<=p; j++) {
dp[i][j] = inf;
if (j>0) {
dp[i][j] = min(dp[i][j], dp[l-1][j-1]);
}
dp[i][j] = min(dp[i][j], dp[r-1][j] + 1);
}
}
return dp[n][p] <= q;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n>>p>>q;
for (int i=1; i<=n; i++) {
cin>>a[i];
}
sort(a+1,a+1+n);
if (p+q>=n) out(1);
int lo=0;
int hi=1e9;
while (hi-lo>1) {
int mid=(lo+hi)/2;
if (test(mid)) {
hi=mid;
} else {
lo=mid;
}
}
cout<<hi<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |