/*
ЗАПУСКАЕМ
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░
*/
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left224
#define right right224
#define next next224
#define rank rank224
#define prev prev224
#define y1 y1224
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define files(FILENAME) read(FILENAME), write(FILENAME)
#define pb push_back
#define mp make_pair
const string FILENAME = "input";
const int MAXN = 2005;
int n, p, q;
int a[MAXN];
int pos[MAXN], pos1[MAXN];
bitset<2001> dp[MAXN][MAXN];
bool can(int x) {
int uk = 0;
for (int i = 0; i < n; i++) {
while (uk + 1 < n && a[i] + x - 1 >= a[uk + 1]) {
uk++;
}
pos[i] = uk;
}
uk = 0;
for (int i = 0; i < n; i++) {
while (uk + 1 < n && a[i] + 2 * x - 1 >= a[uk + 1]) {
uk++;
}
pos1[i] = uk;
}
if (p + q >= n) {
return true;
}
memset(dp, 0, sizeof(dp));
for (int i = 0; i < n; i++) {
for (int cnt = 0; cnt <= p; cnt++) {
dp[i][cnt].reset();
}
}
dp[0][0][0] = true;
for (int i = 0; i < n; i++) {
for (int cnt = 0; cnt <= p; cnt++) {
if (cnt + 1 <= p) {
dp[pos[i] + 1][cnt + 1] |= dp[i][cnt];
}
dp[pos1[i] + 1][cnt] |= dp[i][cnt] << 1;
}
}
for (int cnt = 0; cnt <= p; cnt++) {
for (int cnt1 = 0; cnt1 <= q; cnt1++) {
if (dp[n][cnt][cnt1]) {
return true;
}
}
}
return false;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// /read(FILENAME);
cin >> n >> p >> q;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
int l = 1;
int r = 1000000000;
while (l < r) {
int mid = (l + r) >> 1;
if (can(mid)) {
r = mid;
} else {
l = mid + 1;
}
}
cout << l << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
229 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
219 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |