#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2005;
int dp[N][N];
int n,p, q;
int a[N];
bool poss(ll w)
{
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++) dp[i][j] = 0;
}
int next[N][2];
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < n; j++)
{
int first = a[j];
int add = w - 1;
if (i == 1) add += w;
auto it = upper_bound(a, a + n, first + add);
it--;
next[j][i] = it - a + 1;
}
}
for (int i = p; i >= 0; i--)
{
for (int j = q; j >= 0; j--)
{
if (dp[i][j] == n)
{
dp[0][0] = n;
} else
{
if (i != 0)
{
dp[i - 1][j] = max<int>(next[dp[i][j]][0], dp[i - 1][j]);
}
if (j != 0)
{
dp[i][j - 1] = max<int>(next[dp[i][j]][1], dp[i][j -1]);
}
}
}
}
return dp[0][0] == n;
}
int bs()
{
int a = 2;
int b = 1000000000;
int res = -1;
while (a <= b)
{
int mid = (a + b) / 2;
if (poss(mid))
{
res = mid;
b = mid - 1;
} else
{
a = mid + 1;
}
}
return res;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> p >> q;
for (int i = 0; i < n; i++) cin >> a[i];
if (p + q >= n)
{
cout << 1 << "\n";
return 0;
}
sort(a, a + n);
cout << bs() << "\n";
}
/*
3 1 1
2
11
17
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
139 ms |
16108 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
140 ms |
16108 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
141 ms |
16128 KB |
Output is correct |
8 |
Correct |
140 ms |
16236 KB |
Output is correct |
9 |
Correct |
143 ms |
16108 KB |
Output is correct |
10 |
Correct |
141 ms |
16108 KB |
Output is correct |
11 |
Correct |
142 ms |
16236 KB |
Output is correct |
12 |
Correct |
140 ms |
16236 KB |
Output is correct |
13 |
Correct |
152 ms |
16168 KB |
Output is correct |
14 |
Correct |
139 ms |
16108 KB |
Output is correct |
15 |
Correct |
140 ms |
16108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
144 ms |
16236 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
143 ms |
16108 KB |
Output is correct |
8 |
Correct |
162 ms |
16236 KB |
Output is correct |
9 |
Correct |
176 ms |
16108 KB |
Output is correct |
10 |
Correct |
172 ms |
16108 KB |
Output is correct |
11 |
Correct |
173 ms |
16108 KB |
Output is correct |
12 |
Correct |
314 ms |
16148 KB |
Output is correct |
13 |
Correct |
143 ms |
16108 KB |
Output is correct |
14 |
Correct |
147 ms |
16108 KB |
Output is correct |
15 |
Correct |
145 ms |
16236 KB |
Output is correct |