#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
const int N = 101;
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;
bool yay = true;
for (int i = 0; i < n; ++i) {
cin >> a[i] >> b[i];
if (b[i] != -1) {
cntb += 1;
}
yay &= (a[i] == b[i] || b[i] == -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;
if (yay) {
db ans = inf;
for (int cnt = 0; cnt <= cntb; ++cnt) {
vector<bool> used(n);
db now = 0;
int done = 0;
for (int i = 0; i < cnt; ++i) {
now += b[ob[i]] / (db(i + 1));
used[ob[i]] = true;
done += 1;
}
if (now >= ans) {
continue;
}
for (int i = 0; i < n && done < K; ++i) {
if (!used[oa[i]]) {
done += 1;
now += a[oa[i]] / (db(cnt + 1));
}
}
assert(done >= K);
ans = min(ans, now);
}
cout << fixed << setprecision(10) << ans;
} else {
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);
db ans = inf;
for (int x = 0; x <= r; ++x) {
ans = min(ans, solve(x));
}
cout << fixed << setprecision(20) << ans;
}
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 |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
344 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 |
328 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
596 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
21 |
Correct |
1 ms |
596 KB |
Output is correct |
22 |
Correct |
1 ms |
584 KB |
Output is correct |
23 |
Correct |
1 ms |
596 KB |
Output is correct |
24 |
Correct |
1 ms |
596 KB |
Output is correct |
25 |
Correct |
1 ms |
712 KB |
Output is correct |
26 |
Correct |
1 ms |
588 KB |
Output is correct |
27 |
Correct |
1 ms |
596 KB |
Output is correct |
28 |
Correct |
1 ms |
596 KB |
Output is correct |
29 |
Correct |
1 ms |
596 KB |
Output is correct |
30 |
Correct |
1 ms |
596 KB |
Output is correct |
31 |
Correct |
1 ms |
588 KB |
Output is correct |
32 |
Correct |
1 ms |
596 KB |
Output is correct |
33 |
Correct |
1 ms |
596 KB |
Output is correct |
34 |
Correct |
1 ms |
596 KB |
Output is correct |
35 |
Correct |
1 ms |
584 KB |
Output is correct |
36 |
Correct |
1 ms |
596 KB |
Output is correct |
37 |
Correct |
1 ms |
588 KB |
Output is correct |
38 |
Correct |
1 ms |
596 KB |
Output is correct |
39 |
Correct |
1 ms |
588 KB |
Output is correct |
40 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
596 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
21 |
Correct |
1 ms |
596 KB |
Output is correct |
22 |
Correct |
1 ms |
584 KB |
Output is correct |
23 |
Correct |
1 ms |
596 KB |
Output is correct |
24 |
Correct |
1 ms |
596 KB |
Output is correct |
25 |
Correct |
1 ms |
712 KB |
Output is correct |
26 |
Correct |
1 ms |
588 KB |
Output is correct |
27 |
Correct |
1 ms |
596 KB |
Output is correct |
28 |
Correct |
1 ms |
596 KB |
Output is correct |
29 |
Correct |
1 ms |
596 KB |
Output is correct |
30 |
Correct |
1 ms |
596 KB |
Output is correct |
31 |
Correct |
1 ms |
588 KB |
Output is correct |
32 |
Correct |
1 ms |
596 KB |
Output is correct |
33 |
Correct |
1 ms |
596 KB |
Output is correct |
34 |
Correct |
1 ms |
596 KB |
Output is correct |
35 |
Correct |
1 ms |
584 KB |
Output is correct |
36 |
Correct |
1 ms |
596 KB |
Output is correct |
37 |
Correct |
1 ms |
588 KB |
Output is correct |
38 |
Correct |
1 ms |
596 KB |
Output is correct |
39 |
Correct |
1 ms |
588 KB |
Output is correct |
40 |
Correct |
1 ms |
596 KB |
Output is correct |
41 |
Correct |
2 ms |
1876 KB |
Output is correct |
42 |
Correct |
2 ms |
1876 KB |
Output is correct |
43 |
Correct |
8 ms |
3028 KB |
Output is correct |
44 |
Correct |
7 ms |
3016 KB |
Output is correct |
45 |
Correct |
18 ms |
4612 KB |
Output is correct |
46 |
Correct |
22 ms |
4640 KB |
Output is correct |
47 |
Correct |
33 ms |
5812 KB |
Output is correct |
48 |
Correct |
34 ms |
5828 KB |
Output is correct |
49 |
Correct |
59 ms |
7056 KB |
Output is correct |
50 |
Correct |
50 ms |
7004 KB |
Output is correct |
51 |
Correct |
86 ms |
8324 KB |
Output is correct |
52 |
Correct |
57 ms |
7252 KB |
Output is correct |
53 |
Correct |
34 ms |
5888 KB |
Output is correct |
54 |
Correct |
34 ms |
5844 KB |
Output is correct |
55 |
Correct |
46 ms |
5776 KB |
Output is correct |
56 |
Correct |
33 ms |
5836 KB |
Output is correct |
57 |
Correct |
36 ms |
5824 KB |
Output is correct |
58 |
Correct |
37 ms |
5820 KB |
Output is correct |
59 |
Correct |
35 ms |
5904 KB |
Output is correct |
60 |
Correct |
36 ms |
5836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
2132 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
344 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 |
328 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
0 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
0 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
328 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
468 KB |
Output is correct |
38 |
Correct |
1 ms |
468 KB |
Output is correct |
39 |
Correct |
1 ms |
596 KB |
Output is correct |
40 |
Correct |
1 ms |
596 KB |
Output is correct |
41 |
Correct |
1 ms |
596 KB |
Output is correct |
42 |
Correct |
1 ms |
584 KB |
Output is correct |
43 |
Correct |
1 ms |
596 KB |
Output is correct |
44 |
Correct |
1 ms |
596 KB |
Output is correct |
45 |
Correct |
1 ms |
712 KB |
Output is correct |
46 |
Correct |
1 ms |
588 KB |
Output is correct |
47 |
Correct |
1 ms |
596 KB |
Output is correct |
48 |
Correct |
1 ms |
596 KB |
Output is correct |
49 |
Correct |
1 ms |
596 KB |
Output is correct |
50 |
Correct |
1 ms |
596 KB |
Output is correct |
51 |
Correct |
1 ms |
588 KB |
Output is correct |
52 |
Correct |
1 ms |
596 KB |
Output is correct |
53 |
Correct |
1 ms |
596 KB |
Output is correct |
54 |
Correct |
1 ms |
596 KB |
Output is correct |
55 |
Correct |
1 ms |
584 KB |
Output is correct |
56 |
Correct |
1 ms |
596 KB |
Output is correct |
57 |
Correct |
1 ms |
588 KB |
Output is correct |
58 |
Correct |
1 ms |
596 KB |
Output is correct |
59 |
Correct |
1 ms |
588 KB |
Output is correct |
60 |
Correct |
1 ms |
596 KB |
Output is correct |
61 |
Correct |
2 ms |
1876 KB |
Output is correct |
62 |
Correct |
2 ms |
1876 KB |
Output is correct |
63 |
Correct |
8 ms |
3028 KB |
Output is correct |
64 |
Correct |
7 ms |
3016 KB |
Output is correct |
65 |
Correct |
18 ms |
4612 KB |
Output is correct |
66 |
Correct |
22 ms |
4640 KB |
Output is correct |
67 |
Correct |
33 ms |
5812 KB |
Output is correct |
68 |
Correct |
34 ms |
5828 KB |
Output is correct |
69 |
Correct |
59 ms |
7056 KB |
Output is correct |
70 |
Correct |
50 ms |
7004 KB |
Output is correct |
71 |
Correct |
86 ms |
8324 KB |
Output is correct |
72 |
Correct |
57 ms |
7252 KB |
Output is correct |
73 |
Correct |
34 ms |
5888 KB |
Output is correct |
74 |
Correct |
34 ms |
5844 KB |
Output is correct |
75 |
Correct |
46 ms |
5776 KB |
Output is correct |
76 |
Correct |
33 ms |
5836 KB |
Output is correct |
77 |
Correct |
36 ms |
5824 KB |
Output is correct |
78 |
Correct |
37 ms |
5820 KB |
Output is correct |
79 |
Correct |
35 ms |
5904 KB |
Output is correct |
80 |
Correct |
36 ms |
5836 KB |
Output is correct |
81 |
Runtime error |
3 ms |
2132 KB |
Execution killed with signal 11 |
82 |
Halted |
0 ms |
0 KB |
- |