#include <bits/stdc++.h>
using namespace std;
#define int long long
#define db double
int INF = 0x3f3f3f3f3f3f3f3f;
struct Val {
int a, b, idx;
Val(int x = 0, int y = 0, int z = 0) : a(x), b(y), idx(z) {}
};
bool comp1(const Val& a, const Val& b) {
return (make_pair(a.b, -a.a) < make_pair(b.b, -b.a));
}
bool comp2(const Val& a, const Val& b) {
return (make_pair(a.a, a.idx) < make_pair(b.a, b.idx));
}
const int MAXN = 505;
db dp[MAXN][MAXN];
int32_t main() {
int n, k;
cin >> n >> k;
vector<Val> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i].a >> v[i].b;
if (v[i].b == -1) v[i].b = INF;
v[i].idx = (i + 1);
}
sort(v.begin(), v.end(), comp1);
v.insert(v.begin(), 0);
cout << fixed << setprecision(2);
db ans = INF;
for (int p = 0; p <= k; p++) {
for (int i = 0; i <= k; i++) {
for (int j = 0; j <= k; j++) dp[i][j] = INF;
}
dp[0][0] = 0;
for (int i = 1; i <= k; i++) {
for (int j = 0; j <= i; j++) {
// case 1, we get i to be a companion
if (j > 0) {
db case1 = dp[i - 1][j - 1] + ((db)v[i].b)/((db)j);
dp[i][j] = min(dp[i][j], case1);
}
db case2 = dp[i - 1][j] + ((db)v[i].a)/((db)(p + 1));
dp[i][j] = min(dp[i][j], case2);
}
}
int need = (k - p);
for (int i = 0; i <= need; i++) {
int sumI = 0;
vector<int> rem;
for (int j = (p + i + 1); j <= n; j++) {
rem.push_back(v[j].a);
}
sort(rem.begin(), rem.end());
for (int j = 0; j < (need - i); j++) {
sumI += rem[j];
}
db sum = ((db)sumI)/((db)p+1);
db curr = (sum + dp[p + i][p]);
if (i != need) {
sum -= rem.back();
rem.pop_back();
}
if (curr < ans) {
//cout << sum << " " << i << " " << p << " " << dp[p + 1][p] << "\n";
}
ans = min(ans, curr);
}
}
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
5 ms |
604 KB |
Output is correct |
6 |
Correct |
27 ms |
860 KB |
Output is correct |
7 |
Correct |
103 ms |
1372 KB |
Output is correct |
8 |
Correct |
236 ms |
1880 KB |
Output is correct |
9 |
Correct |
341 ms |
2396 KB |
Output is correct |
10 |
Correct |
165 ms |
1828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
5 ms |
604 KB |
Output is correct |
6 |
Correct |
27 ms |
860 KB |
Output is correct |
7 |
Correct |
103 ms |
1372 KB |
Output is correct |
8 |
Correct |
236 ms |
1880 KB |
Output is correct |
9 |
Correct |
341 ms |
2396 KB |
Output is correct |
10 |
Correct |
165 ms |
1828 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
41 ms |
860 KB |
Output is correct |
13 |
Correct |
86 ms |
1036 KB |
Output is correct |
14 |
Correct |
48 ms |
856 KB |
Output is correct |
15 |
Correct |
185 ms |
1628 KB |
Output is correct |
16 |
Correct |
280 ms |
1628 KB |
Output is correct |
17 |
Correct |
217 ms |
1828 KB |
Output is correct |
18 |
Correct |
341 ms |
2644 KB |
Output is correct |
19 |
Correct |
442 ms |
2396 KB |
Output is correct |
20 |
Correct |
397 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
416 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 |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 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 |
440 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
416 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 |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 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 |
440 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
444 KB |
Output is correct |
16 |
Correct |
1 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 |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
392 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
352 KB |
Output is correct |
27 |
Correct |
0 ms |
360 KB |
Output is correct |
28 |
Correct |
0 ms |
360 KB |
Output is correct |
29 |
Correct |
0 ms |
360 KB |
Output is correct |
30 |
Correct |
0 ms |
360 KB |
Output is correct |
31 |
Correct |
0 ms |
360 KB |
Output is correct |
32 |
Correct |
0 ms |
360 KB |
Output is correct |
33 |
Correct |
0 ms |
360 KB |
Output is correct |
34 |
Correct |
0 ms |
360 KB |
Output is correct |
35 |
Correct |
1 ms |
360 KB |
Output is correct |
36 |
Correct |
0 ms |
360 KB |
Output is correct |
37 |
Correct |
0 ms |
360 KB |
Output is correct |
38 |
Correct |
0 ms |
360 KB |
Output is correct |
39 |
Correct |
0 ms |
360 KB |
Output is correct |
40 |
Correct |
0 ms |
360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
416 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 |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 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 |
440 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
444 KB |
Output is correct |
16 |
Correct |
1 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 |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
392 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
352 KB |
Output is correct |
27 |
Correct |
0 ms |
360 KB |
Output is correct |
28 |
Correct |
0 ms |
360 KB |
Output is correct |
29 |
Correct |
0 ms |
360 KB |
Output is correct |
30 |
Correct |
0 ms |
360 KB |
Output is correct |
31 |
Correct |
0 ms |
360 KB |
Output is correct |
32 |
Correct |
0 ms |
360 KB |
Output is correct |
33 |
Correct |
0 ms |
360 KB |
Output is correct |
34 |
Correct |
0 ms |
360 KB |
Output is correct |
35 |
Correct |
1 ms |
360 KB |
Output is correct |
36 |
Correct |
0 ms |
360 KB |
Output is correct |
37 |
Correct |
0 ms |
360 KB |
Output is correct |
38 |
Correct |
0 ms |
360 KB |
Output is correct |
39 |
Correct |
0 ms |
360 KB |
Output is correct |
40 |
Correct |
0 ms |
360 KB |
Output is correct |
41 |
Correct |
1 ms |
360 KB |
Output is correct |
42 |
Correct |
1 ms |
360 KB |
Output is correct |
43 |
Correct |
1 ms |
356 KB |
Output is correct |
44 |
Correct |
1 ms |
360 KB |
Output is correct |
45 |
Correct |
1 ms |
616 KB |
Output is correct |
46 |
Correct |
2 ms |
616 KB |
Output is correct |
47 |
Correct |
2 ms |
868 KB |
Output is correct |
48 |
Correct |
2 ms |
616 KB |
Output is correct |
49 |
Correct |
3 ms |
604 KB |
Output is correct |
50 |
Correct |
3 ms |
700 KB |
Output is correct |
51 |
Correct |
6 ms |
604 KB |
Output is correct |
52 |
Correct |
4 ms |
600 KB |
Output is correct |
53 |
Correct |
2 ms |
604 KB |
Output is correct |
54 |
Correct |
4 ms |
604 KB |
Output is correct |
55 |
Correct |
2 ms |
856 KB |
Output is correct |
56 |
Correct |
2 ms |
604 KB |
Output is correct |
57 |
Correct |
2 ms |
604 KB |
Output is correct |
58 |
Correct |
2 ms |
604 KB |
Output is correct |
59 |
Correct |
2 ms |
604 KB |
Output is correct |
60 |
Correct |
2 ms |
700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
790 ms |
2428 KB |
Output is correct |
2 |
Correct |
794 ms |
2420 KB |
Output is correct |
3 |
Correct |
793 ms |
2396 KB |
Output is correct |
4 |
Correct |
822 ms |
2396 KB |
Output is correct |
5 |
Correct |
758 ms |
2392 KB |
Output is correct |
6 |
Correct |
775 ms |
2392 KB |
Output is correct |
7 |
Correct |
587 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
5 ms |
604 KB |
Output is correct |
6 |
Correct |
27 ms |
860 KB |
Output is correct |
7 |
Correct |
103 ms |
1372 KB |
Output is correct |
8 |
Correct |
236 ms |
1880 KB |
Output is correct |
9 |
Correct |
341 ms |
2396 KB |
Output is correct |
10 |
Correct |
165 ms |
1828 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
41 ms |
860 KB |
Output is correct |
13 |
Correct |
86 ms |
1036 KB |
Output is correct |
14 |
Correct |
48 ms |
856 KB |
Output is correct |
15 |
Correct |
185 ms |
1628 KB |
Output is correct |
16 |
Correct |
280 ms |
1628 KB |
Output is correct |
17 |
Correct |
217 ms |
1828 KB |
Output is correct |
18 |
Correct |
341 ms |
2644 KB |
Output is correct |
19 |
Correct |
442 ms |
2396 KB |
Output is correct |
20 |
Correct |
397 ms |
2392 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
416 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 |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 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 |
440 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
444 KB |
Output is correct |
36 |
Correct |
1 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 |
0 ms |
344 KB |
Output is correct |
40 |
Correct |
0 ms |
392 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
344 KB |
Output is correct |
43 |
Correct |
0 ms |
600 KB |
Output is correct |
44 |
Correct |
1 ms |
344 KB |
Output is correct |
45 |
Correct |
1 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
352 KB |
Output is correct |
47 |
Correct |
0 ms |
360 KB |
Output is correct |
48 |
Correct |
0 ms |
360 KB |
Output is correct |
49 |
Correct |
0 ms |
360 KB |
Output is correct |
50 |
Correct |
0 ms |
360 KB |
Output is correct |
51 |
Correct |
0 ms |
360 KB |
Output is correct |
52 |
Correct |
0 ms |
360 KB |
Output is correct |
53 |
Correct |
0 ms |
360 KB |
Output is correct |
54 |
Correct |
0 ms |
360 KB |
Output is correct |
55 |
Correct |
1 ms |
360 KB |
Output is correct |
56 |
Correct |
0 ms |
360 KB |
Output is correct |
57 |
Correct |
0 ms |
360 KB |
Output is correct |
58 |
Correct |
0 ms |
360 KB |
Output is correct |
59 |
Correct |
0 ms |
360 KB |
Output is correct |
60 |
Correct |
0 ms |
360 KB |
Output is correct |
61 |
Correct |
1 ms |
360 KB |
Output is correct |
62 |
Correct |
1 ms |
360 KB |
Output is correct |
63 |
Correct |
1 ms |
356 KB |
Output is correct |
64 |
Correct |
1 ms |
360 KB |
Output is correct |
65 |
Correct |
1 ms |
616 KB |
Output is correct |
66 |
Correct |
2 ms |
616 KB |
Output is correct |
67 |
Correct |
2 ms |
868 KB |
Output is correct |
68 |
Correct |
2 ms |
616 KB |
Output is correct |
69 |
Correct |
3 ms |
604 KB |
Output is correct |
70 |
Correct |
3 ms |
700 KB |
Output is correct |
71 |
Correct |
6 ms |
604 KB |
Output is correct |
72 |
Correct |
4 ms |
600 KB |
Output is correct |
73 |
Correct |
2 ms |
604 KB |
Output is correct |
74 |
Correct |
4 ms |
604 KB |
Output is correct |
75 |
Correct |
2 ms |
856 KB |
Output is correct |
76 |
Correct |
2 ms |
604 KB |
Output is correct |
77 |
Correct |
2 ms |
604 KB |
Output is correct |
78 |
Correct |
2 ms |
604 KB |
Output is correct |
79 |
Correct |
2 ms |
604 KB |
Output is correct |
80 |
Correct |
2 ms |
700 KB |
Output is correct |
81 |
Correct |
790 ms |
2428 KB |
Output is correct |
82 |
Correct |
794 ms |
2420 KB |
Output is correct |
83 |
Correct |
793 ms |
2396 KB |
Output is correct |
84 |
Correct |
822 ms |
2396 KB |
Output is correct |
85 |
Correct |
758 ms |
2392 KB |
Output is correct |
86 |
Correct |
775 ms |
2392 KB |
Output is correct |
87 |
Correct |
587 ms |
2392 KB |
Output is correct |
88 |
Correct |
20 ms |
856 KB |
Output is correct |
89 |
Correct |
13 ms |
600 KB |
Output is correct |
90 |
Correct |
105 ms |
860 KB |
Output is correct |
91 |
Correct |
89 ms |
856 KB |
Output is correct |
92 |
Correct |
356 ms |
1372 KB |
Output is correct |
93 |
Correct |
329 ms |
1432 KB |
Output is correct |
94 |
Correct |
603 ms |
1932 KB |
Output is correct |
95 |
Correct |
616 ms |
1880 KB |
Output is correct |
96 |
Correct |
696 ms |
2228 KB |
Output is correct |
97 |
Correct |
742 ms |
2140 KB |
Output is correct |
98 |
Correct |
482 ms |
1832 KB |
Output is correct |
99 |
Correct |
520 ms |
1828 KB |
Output is correct |
100 |
Correct |
528 ms |
1624 KB |
Output is correct |
101 |
Correct |
483 ms |
1628 KB |
Output is correct |
102 |
Correct |
405 ms |
1624 KB |
Output is correct |
103 |
Correct |
406 ms |
1832 KB |
Output is correct |
104 |
Correct |
385 ms |
1624 KB |
Output is correct |
105 |
Correct |
167 ms |
1628 KB |
Output is correct |