이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 2;
int n, p, q, a[N];
int dp[N][N]; // dp[i][j]: number of small cameras needed to take pictures of i events with j big cameras
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> p >> q;
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + n + 1);
if (p + q >= n) return cout << 1 << '\n', 0;
auto binary_func = [&](int x) {
memset(dp, 0x7f, sizeof(dp));
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
int sl = 1, bl = 1;
while (a[i] - a[sl] + 1 > x) sl++;
while (a[i] - a[bl] + 1 > 2 * x) bl++;
for (int j = 0; j <= q; j++) {
dp[i][j] = dp[sl - 1][j] + 1;
if (j > 0) dp[i][j] = min(dp[i][j], dp[bl - 1][j - 1]);
}
}
for (int j = 0; j <= q; j++) if (dp[n][j] <= p) return true;
return false;
};
int lo = 1, hi = n;
while (lo <= hi) {
int mid = (lo + hi) >> 1;
if (binary_func(mid)) hi = mid - 1;
else lo = mid + 1;
}
cout << lo << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |