#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tt;
#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())
int a[2024], dp[2024][2024], prS[2024], prL[2024];
int n, S, L;
bool ok (int w) {
int pS = 0, pL = 0;
for (int i = 1; i <= n; i++) {
while (pS + 1 <= n && a[i] - a[pS + 1] >= w) pS++;
while (pL + 1 <= n && a[i] - a[pL + 1] >= 2 * w) pL++;
prS[i] = pS, prL[i] = pL;
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= L; j++) {
dp[i][j] = dp[prS[i]][j] + 1;
if (j) dp[i][j] = min(dp[i][j], dp[prL[i]][j - 1]);
}
}
return dp[n][L] <= S;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> S >> L;
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + 1 + n);
if (n <= S + L) {
cout << 1;
return 0;
}
int ans = 0;
for (int i = 29; i >= 0; i--) {
int mask = ans | (1 << i);
if (!ok(mask)) ans = mask;
}
cout << ans + 1;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2724 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2648 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
15452 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
15452 KB |
Output is correct |
8 |
Correct |
64 ms |
16120 KB |
Output is correct |
9 |
Correct |
13 ms |
15708 KB |
Output is correct |
10 |
Correct |
10 ms |
15472 KB |
Output is correct |
11 |
Correct |
161 ms |
16216 KB |
Output is correct |
12 |
Correct |
83 ms |
16220 KB |
Output is correct |
13 |
Correct |
4 ms |
15448 KB |
Output is correct |
14 |
Correct |
5 ms |
15452 KB |
Output is correct |
15 |
Correct |
4 ms |
15452 KB |
Output is correct |