#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
#define pb push_back
#define f first
#define s second
const int MAXN = 2e3 + 10;
// dp[i][j] stores maximum number of small cameras left given j large left and all up to i inclusive is taken
int dp[MAXN][MAXN];
int x[MAXN];
int N, P, Q;
set<pi> loc;
bool possible(int w) {
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= Q; j++) {
dp[i][j] = -1;
}
}
dp[0][0] = P;
for (pi cLoc : loc) {
int i = cLoc.s;
for (int nL = 0; nL <= Q; nL++) {
// case 1: use large
if (nL > 0) {
int pI = prev(loc.lower_bound({x[i] - 2 * w + 1, -1}))->s;
dp[i][nL] = max(dp[i][nL], dp[pI][nL - 1]);
}
// case 2: use small
int pI = prev(loc.lower_bound({x[i] - w + 1, -1}))->s;
dp[i][nL] = max(dp[i][nL], dp[pI][nL] - 1);
}
}
int lastI = prev(loc.end())->s;
for (int nL = 0; nL <= Q; nL++) {
if (dp[lastI][nL] >= 0) {
return true;
}
}
return false;
}
int binSearch() {
int low = 1;
int hi = 1e9;
while (low != hi) {
int mid = (low + hi) / 2;
if (possible(mid)) {
hi = mid;
} else {
low = mid + 1;
}
}
return low;
}
int main() {
cin >> N >> P >> Q;
x[0] = -2e9;
loc.insert({x[0], 0});
for (int i = 1; i <= N; i++) {
cin >> x[i];
loc.insert({x[i], i});
}
// cout << possible(9) << endl;
int ans = binSearch();
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
640 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
6 ms |
768 KB |
Output is correct |
5 |
Execution timed out |
1099 ms |
1536 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
8448 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Execution timed out |
1100 ms |
16256 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |