#define taskname "test"
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define fi first
#define se second
typedef long long lli;
typedef pair<int, int> pii;
const int maxn = 2005;
const int inf = 1e9 + 9;
int n, P, Q;
int a[maxn];
int dp[maxn][maxn];
void read_input()
{
cin >> n >> P >> Q;
for(int i = 1; i <= n; ++i)
cin >> a[i];
sort(a + 1, a + n + 1);
}
bool check(int w)
{
fill_n(&dp[0][0], sizeof(dp) / sizeof(dp[0][0]), inf);
dp[0][0] = 0;
int curs1 = 0, curs2 = 0;
for(int i = 1; i <= n; ++i)
{
while(a[i] - a[curs1 + 1] + 1 > w)
++curs1;
while(a[i] - a[curs2 + 1] + 1 > 2 * w)
++curs2;
for(int j = 0; j <= min(i, P); ++j)
{
dp[i][j] = min(dp[i][j], dp[curs2][j] + 1);
if(j > 0) dp[i][j] = min(dp[i][j], dp[curs1][j - 1]);
}
}
for(int j = 0; j <= min(n, P); ++j)
if(dp[n][j] <= Q) return true;
return false;
}
void solve()
{
int low = 1, high = inf;
while(low <= high)
{
int mid = (low + high) / 2;
if(check(mid)) high = mid - 1;
else low = mid + 1;
}
cout << low << '\n';
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
read_input();
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
88 ms |
16108 KB |
Output is correct |
2 |
Correct |
85 ms |
16236 KB |
Output is correct |
3 |
Correct |
100 ms |
16236 KB |
Output is correct |
4 |
Correct |
86 ms |
16236 KB |
Output is correct |
5 |
Correct |
87 ms |
16108 KB |
Output is correct |
6 |
Correct |
86 ms |
16108 KB |
Output is correct |
7 |
Correct |
90 ms |
16108 KB |
Output is correct |
8 |
Correct |
86 ms |
16108 KB |
Output is correct |
9 |
Correct |
88 ms |
16108 KB |
Output is correct |
10 |
Correct |
86 ms |
16108 KB |
Output is correct |
11 |
Correct |
92 ms |
16108 KB |
Output is correct |
12 |
Correct |
90 ms |
16108 KB |
Output is correct |
13 |
Correct |
91 ms |
16108 KB |
Output is correct |
14 |
Correct |
86 ms |
16132 KB |
Output is correct |
15 |
Correct |
86 ms |
16108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
91 ms |
16108 KB |
Output is correct |
2 |
Correct |
86 ms |
16108 KB |
Output is correct |
3 |
Correct |
184 ms |
16236 KB |
Output is correct |
4 |
Correct |
191 ms |
16108 KB |
Output is correct |
5 |
Correct |
99 ms |
16108 KB |
Output is correct |
6 |
Correct |
189 ms |
16108 KB |
Output is correct |
7 |
Correct |
97 ms |
16108 KB |
Output is correct |
8 |
Correct |
107 ms |
16108 KB |
Output is correct |
9 |
Correct |
158 ms |
16108 KB |
Output is correct |
10 |
Correct |
202 ms |
16236 KB |
Output is correct |
11 |
Correct |
103 ms |
16236 KB |
Output is correct |
12 |
Correct |
175 ms |
16108 KB |
Output is correct |
13 |
Correct |
93 ms |
16108 KB |
Output is correct |
14 |
Correct |
92 ms |
16108 KB |
Output is correct |
15 |
Correct |
92 ms |
16236 KB |
Output is correct |