#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
const int N = 501;
db dp[N][N][N]; //id, b, a
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, K;
cin >> n >> K;
vector<int> a(n), b(n), oa(n), ob(n);
int cntb = 0;
for (int i = 0; i < n; ++i) {
cin >> a[i] >> b[i];
if (b[i] != -1) {
cntb += 1;
}
}
iota(oa.begin(), oa.end(), 0), iota(ob.begin(), ob.end(), 0);
sort(oa.begin(), oa.end(), [&a](int i, int j) {
return a[i] < a[j];
});
sort(ob.begin(), ob.end(), [&](int i, int j) {
if (b[i] == -1) return false;
if (b[j] == -1) return true;
return b[i] < b[j];
});
const db inf = 1e12;
auto solve = [&](int mx) -> db {
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= mx; ++j) {
for (int k = 0; k <= K - j; ++k) {
dp[i][j][k] = inf;
}
}
}
dp[0][0][0] = 0;
for (int i = 1; i <= n; ++i) {
//don't take
for (int j = 0; j <= mx; ++j) {
for (int k = 0; k <= min(i, K) - j; ++k) {
dp[i][j][k] = dp[i - 1][j][k];
}
}
//take a
int idx = ob[i - 1];
for (int j = 0; j <= min(i, mx); ++j) {
for (int k = 1; k <= min(i, K) - j; ++k) {
dp[i][j][k] = min(dp[i][j][k], dp[i - 1][j][k - 1] + a[idx] / db(mx + 1));
}
}
if (b[idx] != -1) {
for (int j = 1; j <= min(i, mx); ++j) {
for (int k = 0; k <= min(i, K) - j; ++k) {
dp[i][j][k] = min(dp[i][j][k], dp[i - 1][j - 1][k] + b[idx] / db(j));
}
}
}
}
return dp[n][mx][K - mx];
};
int r = min(K, cntb);
auto check = [&](int x) {
if (x >= r) {
return false;
}
return solve(x + 1) <= solve(x) + 1e-9;
};
int x = 0;
for (int k = 20; k > -1; --k) {
if (check(x + (1 << k))) {
x = x + 1 + (1 << k);
}
}
cout << fixed << setprecision(20) << solve(x);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
4436 KB |
Output is correct |
6 |
Correct |
2 ms |
4684 KB |
Output is correct |
7 |
Correct |
3 ms |
5204 KB |
Output is correct |
8 |
Correct |
3 ms |
5716 KB |
Output is correct |
9 |
Correct |
3 ms |
6100 KB |
Output is correct |
10 |
Correct |
3 ms |
5588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
4436 KB |
Output is correct |
6 |
Correct |
2 ms |
4684 KB |
Output is correct |
7 |
Correct |
3 ms |
5204 KB |
Output is correct |
8 |
Correct |
3 ms |
5716 KB |
Output is correct |
9 |
Correct |
3 ms |
6100 KB |
Output is correct |
10 |
Correct |
3 ms |
5588 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
374 ms |
296316 KB |
Output is correct |
13 |
Incorrect |
584 ms |
257280 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Incorrect |
0 ms |
468 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Incorrect |
0 ms |
468 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Incorrect |
0 ms |
468 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2592 ms |
761588 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
4436 KB |
Output is correct |
6 |
Correct |
2 ms |
4684 KB |
Output is correct |
7 |
Correct |
3 ms |
5204 KB |
Output is correct |
8 |
Correct |
3 ms |
5716 KB |
Output is correct |
9 |
Correct |
3 ms |
6100 KB |
Output is correct |
10 |
Correct |
3 ms |
5588 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
374 ms |
296316 KB |
Output is correct |
13 |
Incorrect |
584 ms |
257280 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |