이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
using namespace std;
typedef long long ll;
int n, p, q;
ll a[2001];
ll dp[2001][2001]; // Max position you can get up to with at most i small and j big
// You clearly need at most N cameras
bool assign(ll w) {
dp[0][0] = 0;
int ii = 1, jj = 1;
FOR(i, 0, min(p, n) + 1) {
while (a[i] - a[ii] + 1 > w) ii++;
while (a[i] - a[jj] + 1 > 2 * w) jj++;
FOR(j, 0, min(q, n) + 1) {
if (j == 0) dp[i][j] = dp[jj - 1][j] + 1;
else {
dp[i][j] = min(dp[jj - 1][j] + 1, dp[ii - 1][j - 1]);
dp[i][j] = min(dp[i][j], dp[i][j - 1]);
}
}
}
return dp[min(n, p)][min(n, q)] >= a[n];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> p >> q;
FOR(i, 1, n + 1) cin >> a[i];
sort(a + 1, a + n + 1);
ll l = 1, r = a[n] - a[1];
while (l != r) {
// cout << l << ' ' << r << endl;
ll mid = (l + r) / 2;
if (assign(mid)) r = mid;
else l = mid + 1;
}
cout << l << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |