#include<bits/stdc++.h>
using namespace std;
using int64 = int64_t;
#define FOR(i, l, r) for(int i = (l), _r = (r); i <= _r; ++i)
#define FORD(i, r, l) for(int i = (r), _l = (l); i >= _l; --i)
#define rep(i, l, r) for(int i = (l), _r = (r); i < _r; ++i)
#define repd(i, r, l) for(int i = (r) - 1, _l = l; i >= _l; --i)
#define left __left
#define right __right
#define next __next
#define prev __prev
#define div __div
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()
#define compact(v) v.erase(unique(all(v)), end(v))
#define dbg(v) "[" #v " = " << (v) << "]"
#define file(name) if(fopen(name".inp", "r")) {freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
template<typename T>
bool minimize(T& a, const T& b){
if(a > b) return a = b, true;
return false;
}
template<typename T>
bool maximize(T& a, const T& b){
if(a < b) return a = b, true;
return false;
}
template<int dimension, typename T>
struct vec : public vector<vec<dimension - 1, T>> {
static_assert(dimension > 0, "Dimension must be positive !\n");
template<typename... Args>
vec(int n = 0, Args... args) : vector<vec<dimension - 1, T>> (n, vec<dimension - 1, T>(args...)) {}
};
template<typename T>
struct vec<1, T> : public vector<T> {
vec(int n = 0, T val = T()) : vector<T>(n, val) {}
};
void preprocess();
void init();
void process();
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
file("antuvu");
preprocess();
int T = 1; //cin >> T;
while(T--){
init();
process();
}
return 0;
}
const int MAX = 2e3 + 5;
int n, p, q, a[MAX], reach_w[MAX], reach_2w[MAX], dp[MAX][MAX];
void preprocess(){
}
void init(){
cin >> n >> p >> q;
for(int i = 1; i <= n; ++i){
cin >> a[i];
}
}
bool f(int w){
for(int i = 1, j = 1, k = 1; i <= n; ++i){
while(j < n && a[j + 1] - a[i] + 1 <= w){
++j;
}
reach_w[i] = j;
while(k < n && a[k + 1] - a[i] + 1 <= 2 * w){
++k;
}
reach_2w[i] = k;
}
if(reach_w[1] == n || reach_2w[1] == n) return true;
memset(dp, -1, sizeof(dp));
dp[0][1] = reach_2w[1];
dp[1][0] = reach_w[1];
for(int i = 0; i <= p; ++i){
for(int j = 0; j <= q; ++j) if(i || j){
if(dp[i][j] == n){
return true;
}
dp[i + 1][j] = max(dp[i + 1][j], reach_w[dp[i][j] + 1]);
dp[i][j + 1] = max(dp[i][j + 1], reach_2w[dp[i][j] + 1]);
}
}
return false;
}
void process(){
if(p + q >= n){
cout << 1 << '\n';
return;
}
sort(a + 1, a + 1 + n);
int l = 1, r = 1e9, ans = r;
while(l <= r){
int mid = l + r >> 1;
if(f(mid)) ans = mid, r = mid - 1;
else l = mid + 1;
}
cout << ans << '\n';
}
Compilation message
watching.cpp: In function 'void process()':
watching.cpp:127:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
127 | int mid = l + r >> 1;
| ~~^~~
watching.cpp: In function 'int main()':
watching.cpp:21:58: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | #define file(name) if(fopen(name".inp", "r")) {freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
watching.cpp:55:5: note: in expansion of macro 'file'
55 | file("antuvu");
| ^~~~
watching.cpp:21:91: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | #define file(name) if(fopen(name".inp", "r")) {freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
watching.cpp:55:5: note: in expansion of macro 'file'
55 | file("antuvu");
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
15964 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
22 ms |
16200 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
22 ms |
16204 KB |
Output is correct |
8 |
Correct |
26 ms |
16336 KB |
Output is correct |
9 |
Correct |
23 ms |
15964 KB |
Output is correct |
10 |
Correct |
22 ms |
15964 KB |
Output is correct |
11 |
Correct |
30 ms |
15964 KB |
Output is correct |
12 |
Correct |
24 ms |
15964 KB |
Output is correct |
13 |
Correct |
14 ms |
15960 KB |
Output is correct |
14 |
Correct |
14 ms |
16076 KB |
Output is correct |
15 |
Correct |
20 ms |
15960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
16472 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
30 ms |
16220 KB |
Output is correct |
8 |
Correct |
30 ms |
16220 KB |
Output is correct |
9 |
Correct |
31 ms |
16220 KB |
Output is correct |
10 |
Correct |
33 ms |
16216 KB |
Output is correct |
11 |
Correct |
27 ms |
16220 KB |
Output is correct |
12 |
Correct |
63 ms |
16220 KB |
Output is correct |
13 |
Correct |
20 ms |
16220 KB |
Output is correct |
14 |
Correct |
21 ms |
16220 KB |
Output is correct |
15 |
Correct |
22 ms |
16220 KB |
Output is correct |