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<class C>constexpr int len(const C&c){return int(c.size());}
const int MAXN = 2003;
int N, P, Q;
long long W, arr[MAXN], dp[MAXN][MAXN];
int helper(int pos, int left, long long loc){
if(pos == N) return 0;
//cout << pos << " " << left << " " << loc << endl;
if(loc > arr[pos]) return helper(pos + 1, left, loc);
if(dp[pos][left] != -1) return dp[pos][left];
int ans = helper(pos + 1, left, arr[pos] + W + W) + 1;
if(left > 0) ans = min(ans, helper(pos + 1, left - 1, arr[pos] + W));
return dp[pos][left] = ans;
}
bool check(long long w){
memset(dp, -1, sizeof(dp)); W = w;
return helper(0, P, 0) <= Q;
}
int main(){
cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("haybales.in", "r", stdin);
//freopen("haybales.out", "w", stdout);
// Bsearch on answer
// Check:
// DP[i][j] = Minimum large cameras for first i and j small cameras
cin >> N >> P >> Q;
if(P + Q >= N){ // thanks JOI
cout << "1\n"; return 0;
}
for(int i = 0; i < N; ++i) cin >> arr[i];
sort(arr, arr + N);
long long mid, left = -1, right = 1e9 + 1;
while(right - left > 1){
mid = left + (right - left) / 2LL;
if(check(mid)) right = mid;
else left = mid;
}
cout << right << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |