#include <bits/stdc++.h>
#define ll long long
#define ar array
#define db double
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rint(l, r) uniform_int_distribution<int>(l, r)(rng)
template<typename T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
void test_case() {
int n, k;
cin >> n >> k;
vector<ar<int, 2>> a(n);
for (auto &x : a) cin >> x[0] >> x[1];
if (n == k) {
db ans = 1e18;
int cnt = 0;
for (int i = 0; i < n; i++) cnt += bool(~a[i][1]);
sort(all(a), [&](const auto &A, const auto &B) { return A[1] < B[1]; });
for (int i = 1; i <= min(cnt, k) + 1; i++) {
// use i people in the end
vector<db> dp(i+1, 1e18);
dp[1] = 0;
for (int j = 0; j < n; j++) {
vector<db> dp2(i+1, 1e18);
for (int l = 1; l <= i; l++) {
if (~a[j][1] && l + 1 <= i) {
ckmin(dp2[l+1], dp[l] + (db)a[j][1] / l);
}
ckmin(dp2[l], dp[l] + (db)a[j][0] / i);
}
swap(dp, dp2);
}
ckmin(ans, dp[i]);
}
cout << fixed << setprecision(10) << ans << '\n';
return;
}
// let us use z people in the end
// then, we must first take z-1 Bs, and those Bs will be taken in increasing order
// As must be taken afterwards and can be taken in arbitrary order
db ans = 1e18;
int cnt = 0;
for (int i = 0; i < n; i++) cnt += bool(~a[i][1]);
sort(all(a), [&](const auto &A, const auto &B) { return A[1] < B[1]; });
vector<db> mem(1000, -1);
auto get = [&](int i) {
if (mem[i] != -1) return mem[i];
vector<vector<db>> dp(k+1, vector<db>(i+1, 1e18));
dp[0][1] = 0;
for (int j = 0; j < n; j++) {
for (int got = min(j+1, k)-1; got >= 0; got--) {
for (int l = 1; l <= min(j+1, i); l++) {
if (~a[j][1] && l + 1 <= i) {
ckmin(dp[got+1][l+1], dp[got][l] + (db)a[j][1] / l);
}
ckmin(dp[got+1][l], dp[got][l] + (db)a[j][0] / i);
}
}
}
return mem[i] = dp[k][i];
};
int L = 1, R = min(cnt, k) + 1;
while (R - L >= 3) {
int mid = (L+R)/2;
if (get(mid) < get(mid+1)) R = mid;
else L = mid+1;
}
for (int i = L; i <= R; i++) ckmin(ans, get(i));
cout << fixed << setprecision(10) << ans << '\n';
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int t = 1;
// cin >> t;
while (t--) test_case();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
169 ms |
648 KB |
Output is correct |
13 |
Correct |
117 ms |
856 KB |
Output is correct |
14 |
Correct |
37 ms |
348 KB |
Output is correct |
15 |
Correct |
742 ms |
1616 KB |
Output is correct |
16 |
Correct |
498 ms |
1060 KB |
Output is correct |
17 |
Correct |
151 ms |
728 KB |
Output is correct |
18 |
Correct |
149 ms |
348 KB |
Output is correct |
19 |
Correct |
52 ms |
344 KB |
Output is correct |
20 |
Correct |
5 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
0 ms |
344 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
0 ms |
344 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
1 ms |
600 KB |
Output is correct |
45 |
Correct |
3 ms |
348 KB |
Output is correct |
46 |
Correct |
2 ms |
348 KB |
Output is correct |
47 |
Correct |
2 ms |
348 KB |
Output is correct |
48 |
Correct |
6 ms |
348 KB |
Output is correct |
49 |
Correct |
5 ms |
600 KB |
Output is correct |
50 |
Correct |
4 ms |
348 KB |
Output is correct |
51 |
Correct |
2 ms |
348 KB |
Output is correct |
52 |
Correct |
1 ms |
600 KB |
Output is correct |
53 |
Correct |
2 ms |
348 KB |
Output is correct |
54 |
Correct |
3 ms |
348 KB |
Output is correct |
55 |
Correct |
4 ms |
508 KB |
Output is correct |
56 |
Correct |
2 ms |
348 KB |
Output is correct |
57 |
Correct |
3 ms |
348 KB |
Output is correct |
58 |
Correct |
4 ms |
344 KB |
Output is correct |
59 |
Correct |
4 ms |
348 KB |
Output is correct |
60 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
157 ms |
520 KB |
Output is correct |
2 |
Correct |
156 ms |
512 KB |
Output is correct |
3 |
Correct |
151 ms |
516 KB |
Output is correct |
4 |
Correct |
153 ms |
772 KB |
Output is correct |
5 |
Correct |
150 ms |
528 KB |
Output is correct |
6 |
Correct |
154 ms |
344 KB |
Output is correct |
7 |
Correct |
151 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
169 ms |
648 KB |
Output is correct |
13 |
Correct |
117 ms |
856 KB |
Output is correct |
14 |
Correct |
37 ms |
348 KB |
Output is correct |
15 |
Correct |
742 ms |
1616 KB |
Output is correct |
16 |
Correct |
498 ms |
1060 KB |
Output is correct |
17 |
Correct |
151 ms |
728 KB |
Output is correct |
18 |
Correct |
149 ms |
348 KB |
Output is correct |
19 |
Correct |
52 ms |
344 KB |
Output is correct |
20 |
Correct |
5 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
596 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
344 KB |
Output is correct |
42 |
Correct |
1 ms |
344 KB |
Output is correct |
43 |
Correct |
0 ms |
344 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
0 ms |
344 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
1 ms |
348 KB |
Output is correct |
55 |
Correct |
1 ms |
344 KB |
Output is correct |
56 |
Correct |
0 ms |
344 KB |
Output is correct |
57 |
Correct |
0 ms |
348 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
1 ms |
348 KB |
Output is correct |
62 |
Correct |
1 ms |
348 KB |
Output is correct |
63 |
Correct |
1 ms |
348 KB |
Output is correct |
64 |
Correct |
1 ms |
600 KB |
Output is correct |
65 |
Correct |
3 ms |
348 KB |
Output is correct |
66 |
Correct |
2 ms |
348 KB |
Output is correct |
67 |
Correct |
2 ms |
348 KB |
Output is correct |
68 |
Correct |
6 ms |
348 KB |
Output is correct |
69 |
Correct |
5 ms |
600 KB |
Output is correct |
70 |
Correct |
4 ms |
348 KB |
Output is correct |
71 |
Correct |
2 ms |
348 KB |
Output is correct |
72 |
Correct |
1 ms |
600 KB |
Output is correct |
73 |
Correct |
2 ms |
348 KB |
Output is correct |
74 |
Correct |
3 ms |
348 KB |
Output is correct |
75 |
Correct |
4 ms |
508 KB |
Output is correct |
76 |
Correct |
2 ms |
348 KB |
Output is correct |
77 |
Correct |
3 ms |
348 KB |
Output is correct |
78 |
Correct |
4 ms |
344 KB |
Output is correct |
79 |
Correct |
4 ms |
348 KB |
Output is correct |
80 |
Correct |
3 ms |
348 KB |
Output is correct |
81 |
Correct |
157 ms |
520 KB |
Output is correct |
82 |
Correct |
156 ms |
512 KB |
Output is correct |
83 |
Correct |
151 ms |
516 KB |
Output is correct |
84 |
Correct |
153 ms |
772 KB |
Output is correct |
85 |
Correct |
150 ms |
528 KB |
Output is correct |
86 |
Correct |
154 ms |
344 KB |
Output is correct |
87 |
Correct |
151 ms |
348 KB |
Output is correct |
88 |
Correct |
6 ms |
348 KB |
Output is correct |
89 |
Correct |
15 ms |
596 KB |
Output is correct |
90 |
Correct |
51 ms |
540 KB |
Output is correct |
91 |
Correct |
105 ms |
580 KB |
Output is correct |
92 |
Correct |
208 ms |
640 KB |
Output is correct |
93 |
Correct |
410 ms |
916 KB |
Output is correct |
94 |
Correct |
461 ms |
964 KB |
Output is correct |
95 |
Correct |
816 ms |
1440 KB |
Output is correct |
96 |
Correct |
802 ms |
1612 KB |
Output is correct |
97 |
Correct |
996 ms |
1696 KB |
Output is correct |
98 |
Correct |
351 ms |
1208 KB |
Output is correct |
99 |
Correct |
193 ms |
852 KB |
Output is correct |
100 |
Correct |
459 ms |
984 KB |
Output is correct |
101 |
Correct |
591 ms |
1132 KB |
Output is correct |
102 |
Correct |
727 ms |
1316 KB |
Output is correct |
103 |
Correct |
699 ms |
1244 KB |
Output is correct |
104 |
Correct |
626 ms |
1128 KB |
Output is correct |
105 |
Correct |
145 ms |
1108 KB |
Output is correct |