/**
* author : pham van sam
* created : 28 June 2023 (Wednesday)
**/
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0, _n = n; i < _n; ++i)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define FORE(it, s) for (__typeof(s.begin()) it = (s).begin(); it != (s).end(); ++it)
template <typename U, typename V> bool maximize(U &A, const V &B) { return (A < B) ? (A = B, true) : false; }
template <typename U, typename V> bool minimize(U &A, const V &B) { return (A > B) ? (A = B, true) : false; }
const int MAXN = 2e3 + 5;
int N, P, Q, a[MAXN];
int dp[MAXN][MAXN], nxt1[MAXN], nxt2[MAXN];
bool check(int w) {
FOR(i, 0, P) FOR(j, 0, Q) dp[i][j] = 0;
FOR(i, 0, N) {
nxt1[i] = upper_bound(a + 1, a + N + 1, a[i] + w - 1) - a;
nxt2[i] = upper_bound(a + 1, a + N + 1, a[i] + 2 * w - 1) - a;
}
nxt1[0] = nxt1[1], nxt2[0] = nxt2[1];
FOR(i, 0, P) FOR(j, 0, Q) {
maximize(dp[i + 1][j], nxt1[dp[i][j]]);
maximize(dp[i][j + 1], nxt2[dp[i][j]]);
if(dp[i][j] >= N) return true;
}
return false;
}
void process(void) {
cin >> N >> P >> Q;
if(N <= P + Q) return void(cout << 1);
FOR(i, 1, N) cin >> a[i];
sort(a + 1, a + N + 1);
int l = 0, r = 1e9;
while(r - l > 1) {
int mid = (l + r) >> 1;
if(check(mid)) r = mid;
else l = mid;
}
cout << r << '\n';
}
signed main() {
#define TASK "watching"
if(fopen(TASK".inp", "r")) {
freopen(TASK".inp", "r", stdin);
freopen(TASK".out", "w", stdout);
}
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
auto start_time = steady_clock::now();
int test = 1;
// cin >> test;
for (int i = 1; i <= test; ++i) {
process();
// cout << '\n';
}
auto end_time = steady_clock::now();
cerr << "\nExecution time : " << duration_cast<milliseconds> (end_time - start_time).count() << "[ms]" << endl;
return (0 ^ 0);
}
Compilation message
watching.cpp: In function 'int main()':
watching.cpp:60:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
60 | freopen(TASK".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
watching.cpp:61:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
61 | freopen(TASK".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |