#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
#define int long long
const int maxn = 2010;
int dp[maxn][maxn];
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while(tt--) {
int n, p, q;
cin >> n >> p >> q;
int a[n + 1];
for(int i = 1;i <= n;i++)
cin >> a[i];
sort(a + 1, a + n + 1);
p = min(p, n);
q = min(q, n);
auto idiUkurac = [&](int x, int z) {
int l = x, r = n, res = x;
while(l <= r) {
int mid = (l + r) / 2;
if(a[mid] - a[x] + 1 <= z) {
res = mid;
l = mid + 1;
}
else
r = mid - 1;
}
return res;
};
auto check = [&](int x) {
for(int i = 0;i <= p;i++)
for(int j = 0;j <= q;j++)
dp[i][j] = 0;
for(int i = 0;i <= p;i++) {
for(int j = 0;j <= q;j++) {
dp[i + 1][j] = max(dp[i + 1][j], idiUkurac(dp[i][j] + 1, x));
dp[i][j + 1] = max(dp[i][j + 1], idiUkurac(dp[i][j] + 1, 2 * x));
}
}
return dp[p][q] >= n;
};
int l = 1, r = 1e9, ans = -1;
while(l <= r) {
int mid = (l + r) / 2;
if(check(mid)) {
ans = mid;
r = mid - 1;
}
else
l = mid + 1;
}
//TEBI U KRILU KURVA A MENI MALO PRASE????
cout << ans << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
724 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
324 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
605 ms |
23968 KB |
Output is correct |
4 |
Correct |
70 ms |
9632 KB |
Output is correct |
5 |
Correct |
64 ms |
1584 KB |
Output is correct |
6 |
Correct |
833 ms |
31836 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
56 ms |
1588 KB |
Output is correct |
9 |
Correct |
60 ms |
4108 KB |
Output is correct |
10 |
Correct |
85 ms |
9300 KB |
Output is correct |
11 |
Correct |
79 ms |
1756 KB |
Output is correct |
12 |
Correct |
437 ms |
11732 KB |
Output is correct |
13 |
Correct |
1 ms |
420 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |