#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define siz(x) (int)x.size()
#define ms(x, a) memset(x, a, sizeof(x))
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values){
cout << vars << " = ";
string delim = "";
(...,(cout << delim << values, delim = ", "));
cout << endl;
}
const int INF = 0x3f3f3f3f;
//==================================
const int MAX = 105;
int arr[MAX], dp[MAX][MAX][MAX], n, p, q;
inline int bs(int i, int x){
int l = 0, r = i;
while (l+1 < r){
int m = l+(r-l)/2;
if (arr[i]-arr[m]+1 <= x) r = m; else l = m;
}
return r;
}
bool good(int w){
int a = p, b = q, curr = -INF;
ms(dp, 0); for (int i = 0; i <= p; i++) for (int j = 0; j <= q; j++) dp[0][i][j] = 1;
for (int i = 1; i <= n; i++){
int x = bs(i, w)-1, y = bs(i, 2*w)-1;
for (int j = 0; j <= p; j++){
for (int k = 0; k <= q; k++){
if (j) dp[i][j][k] |= dp[x][j-1][k];
if (k) dp[i][j][k] |= dp[y][j][k-1];
}
}
}
return dp[n][p][q];
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> p >> q;
if (p+q >= n){ cout << 1 << "\n"; return 0; }
for (int i = 1; i <= n; i++) cin >> arr[i];
sort(arr+1, arr+n+1);
int l = 1, r = INF;
while (l+1 < r){
int m = l+(r-l)/2;
(good(m)? r : l) = m;
}
cout << r << "\n";
}
Compilation message
watching.cpp: In function 'bool good(int)':
watching.cpp:32:9: warning: unused variable 'a' [-Wunused-variable]
32 | int a = p, b = q, curr = -INF;
| ^
watching.cpp:32:16: warning: unused variable 'b' [-Wunused-variable]
32 | int a = p, b = q, curr = -INF;
| ^
watching.cpp:32:23: warning: unused variable 'curr' [-Wunused-variable]
32 | int a = p, b = q, curr = -INF;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4820 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
5 ms |
4812 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
5 ms |
4820 KB |
Output is correct |
8 |
Correct |
6 ms |
4808 KB |
Output is correct |
9 |
Correct |
6 ms |
4860 KB |
Output is correct |
10 |
Correct |
9 ms |
4860 KB |
Output is correct |
11 |
Correct |
11 ms |
4820 KB |
Output is correct |
12 |
Correct |
16 ms |
4852 KB |
Output is correct |
13 |
Correct |
6 ms |
4820 KB |
Output is correct |
14 |
Correct |
5 ms |
4820 KB |
Output is correct |
15 |
Correct |
6 ms |
4808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |