#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]; });
auto get = [&](int 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 = k-1; got >= 0; got--) {
for (int l = 1; l <= 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 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 |
460 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
456 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
456 KB |
Output is correct |
10 |
Correct |
1 ms |
600 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 |
460 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
456 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
456 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
274 ms |
608 KB |
Output is correct |
13 |
Correct |
183 ms |
596 KB |
Output is correct |
14 |
Correct |
64 ms |
520 KB |
Output is correct |
15 |
Correct |
1704 ms |
1400 KB |
Output is correct |
16 |
Correct |
1016 ms |
1144 KB |
Output is correct |
17 |
Correct |
291 ms |
732 KB |
Output is correct |
18 |
Correct |
184 ms |
348 KB |
Output is correct |
19 |
Correct |
65 ms |
592 KB |
Output is correct |
20 |
Correct |
6 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
500 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 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 |
1 ms |
500 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
352 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 |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
500 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
404 KB |
Output is correct |
33 |
Correct |
1 ms |
356 KB |
Output is correct |
34 |
Correct |
0 ms |
356 KB |
Output is correct |
35 |
Correct |
1 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 |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
500 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
352 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 |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
500 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
404 KB |
Output is correct |
33 |
Correct |
1 ms |
356 KB |
Output is correct |
34 |
Correct |
0 ms |
356 KB |
Output is correct |
35 |
Correct |
1 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 |
0 ms |
344 KB |
Output is correct |
41 |
Correct |
1 ms |
344 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
2 ms |
348 KB |
Output is correct |
45 |
Correct |
10 ms |
348 KB |
Output is correct |
46 |
Correct |
3 ms |
348 KB |
Output is correct |
47 |
Correct |
4 ms |
348 KB |
Output is correct |
48 |
Correct |
8 ms |
344 KB |
Output is correct |
49 |
Correct |
12 ms |
348 KB |
Output is correct |
50 |
Correct |
7 ms |
348 KB |
Output is correct |
51 |
Correct |
2 ms |
348 KB |
Output is correct |
52 |
Correct |
2 ms |
348 KB |
Output is correct |
53 |
Correct |
3 ms |
348 KB |
Output is correct |
54 |
Correct |
5 ms |
348 KB |
Output is correct |
55 |
Correct |
9 ms |
344 KB |
Output is correct |
56 |
Correct |
3 ms |
344 KB |
Output is correct |
57 |
Correct |
7 ms |
348 KB |
Output is correct |
58 |
Correct |
8 ms |
512 KB |
Output is correct |
59 |
Correct |
8 ms |
348 KB |
Output is correct |
60 |
Correct |
11 ms |
500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
267 ms |
344 KB |
Output is correct |
2 |
Correct |
167 ms |
516 KB |
Output is correct |
3 |
Correct |
172 ms |
508 KB |
Output is correct |
4 |
Correct |
170 ms |
348 KB |
Output is correct |
5 |
Correct |
168 ms |
348 KB |
Output is correct |
6 |
Correct |
177 ms |
596 KB |
Output is correct |
7 |
Correct |
170 ms |
516 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 |
460 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
456 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
456 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
274 ms |
608 KB |
Output is correct |
13 |
Correct |
183 ms |
596 KB |
Output is correct |
14 |
Correct |
64 ms |
520 KB |
Output is correct |
15 |
Correct |
1704 ms |
1400 KB |
Output is correct |
16 |
Correct |
1016 ms |
1144 KB |
Output is correct |
17 |
Correct |
291 ms |
732 KB |
Output is correct |
18 |
Correct |
184 ms |
348 KB |
Output is correct |
19 |
Correct |
65 ms |
592 KB |
Output is correct |
20 |
Correct |
6 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
500 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
1 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 |
1 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 |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
352 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 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 |
1 ms |
500 KB |
Output is correct |
49 |
Correct |
0 ms |
344 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
1 ms |
404 KB |
Output is correct |
53 |
Correct |
1 ms |
356 KB |
Output is correct |
54 |
Correct |
0 ms |
356 KB |
Output is correct |
55 |
Correct |
1 ms |
348 KB |
Output is correct |
56 |
Correct |
0 ms |
348 KB |
Output is correct |
57 |
Correct |
0 ms |
348 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
0 ms |
344 KB |
Output is correct |
61 |
Correct |
1 ms |
344 KB |
Output is correct |
62 |
Correct |
1 ms |
348 KB |
Output is correct |
63 |
Correct |
1 ms |
348 KB |
Output is correct |
64 |
Correct |
2 ms |
348 KB |
Output is correct |
65 |
Correct |
10 ms |
348 KB |
Output is correct |
66 |
Correct |
3 ms |
348 KB |
Output is correct |
67 |
Correct |
4 ms |
348 KB |
Output is correct |
68 |
Correct |
8 ms |
344 KB |
Output is correct |
69 |
Correct |
12 ms |
348 KB |
Output is correct |
70 |
Correct |
7 ms |
348 KB |
Output is correct |
71 |
Correct |
2 ms |
348 KB |
Output is correct |
72 |
Correct |
2 ms |
348 KB |
Output is correct |
73 |
Correct |
3 ms |
348 KB |
Output is correct |
74 |
Correct |
5 ms |
348 KB |
Output is correct |
75 |
Correct |
9 ms |
344 KB |
Output is correct |
76 |
Correct |
3 ms |
344 KB |
Output is correct |
77 |
Correct |
7 ms |
348 KB |
Output is correct |
78 |
Correct |
8 ms |
512 KB |
Output is correct |
79 |
Correct |
8 ms |
348 KB |
Output is correct |
80 |
Correct |
11 ms |
500 KB |
Output is correct |
81 |
Correct |
267 ms |
344 KB |
Output is correct |
82 |
Correct |
167 ms |
516 KB |
Output is correct |
83 |
Correct |
172 ms |
508 KB |
Output is correct |
84 |
Correct |
170 ms |
348 KB |
Output is correct |
85 |
Correct |
168 ms |
348 KB |
Output is correct |
86 |
Correct |
177 ms |
596 KB |
Output is correct |
87 |
Correct |
170 ms |
516 KB |
Output is correct |
88 |
Correct |
8 ms |
344 KB |
Output is correct |
89 |
Correct |
21 ms |
344 KB |
Output is correct |
90 |
Correct |
72 ms |
348 KB |
Output is correct |
91 |
Correct |
170 ms |
564 KB |
Output is correct |
92 |
Correct |
358 ms |
640 KB |
Output is correct |
93 |
Correct |
722 ms |
1108 KB |
Output is correct |
94 |
Correct |
939 ms |
1128 KB |
Output is correct |
95 |
Correct |
1706 ms |
1548 KB |
Output is correct |
96 |
Correct |
1949 ms |
1640 KB |
Output is correct |
97 |
Execution timed out |
2544 ms |
1864 KB |
Time limit exceeded |
98 |
Halted |
0 ms |
0 KB |
- |