#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <queue>
using namespace std;
typedef long long ll;
int N, p, q, a;
vector<ll> arr;
int func(ll w, int cur = 0, int sw = p, int bw = q) {
if (sw <= 0 && bw <= 0) return 0;
if (cur >= arr.size()) return 1;
bool chk1 = 0, chk2 = 0;
for (int i = cur+1; i < arr.size(); ++i) {
if (arr[i] - arr[cur] + 1 > w && chk1 == 0 && sw) {
chk1 = 1;
if (func(w, i, sw - 1, bw)) return 1;
}
if (arr[i] - arr[cur] + 1 > 2 * w && chk2 == 0 && bw) {
chk2 = 1;
if (func(w, i, sw, bw - 1)) return 1;
}
}
if (chk1 == 0 && sw) return 1;
if (chk2 == 0 && bw) return 1;
return 0;
}
int main() {
cin.tie(NULL);
ios::sync_with_stdio(false);
cin >> N;
cin >> p >> q;
for (int i = 0; i < N; ++i) {
cin >> a;
arr.push_back(a);
}
sort(arr.begin(), arr.end());
arr.resize(distance(arr.begin(), unique(arr.begin(), arr.end())));
ll x = 1, y = 1000000000, mid, res;
while (x <= y) {
mid = (x + y) >> 1;
if (func(mid)) {
y = mid - 1;
res = mid;
}
else {
x = mid + 1;
}
}
cout << res;
}
Compilation message
watching.cpp: In function 'int func(ll, int, int, int)':
watching.cpp:13:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (cur >= arr.size()) return 1;
~~~~^~~~~~~~~~~~~
watching.cpp:15:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = cur+1; i < arr.size(); ++i) {
~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
484 KB |
Output is correct |
4 |
Correct |
3 ms |
484 KB |
Output is correct |
5 |
Correct |
2 ms |
484 KB |
Output is correct |
6 |
Correct |
3 ms |
528 KB |
Output is correct |
7 |
Correct |
3 ms |
536 KB |
Output is correct |
8 |
Correct |
54 ms |
536 KB |
Output is correct |
9 |
Correct |
28 ms |
536 KB |
Output is correct |
10 |
Execution timed out |
1083 ms |
536 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
552 KB |
Output is correct |
2 |
Correct |
4 ms |
552 KB |
Output is correct |
3 |
Correct |
4 ms |
816 KB |
Output is correct |
4 |
Correct |
5 ms |
816 KB |
Output is correct |
5 |
Correct |
4 ms |
816 KB |
Output is correct |
6 |
Correct |
3 ms |
848 KB |
Output is correct |
7 |
Execution timed out |
1080 ms |
848 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |