#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target("avx,avx2,fma")
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using ld = long double; // or double, if TL is tight
using str = string;
using ii = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
int n, k;
cin >> n >> k;
vector<ii> V(n);
for(int i = 0; i < n; ++i) {
cin >> V[i].first >> V[i].second;
if(V[i].second == -1) V[i].second = 1e9;
}
sort(all(V), [&](auto a, auto b) {
if(a.second != b.second) return a.second < b.second;
return a < b;
});
vi A(n), B(n);
for(int i = 0; i < n; ++i) {
A[i] = V[i].first;
B[i] = V[i].second;
}
const ld INF = 1e18;
vector<vector<ld> > DP(n, vector<ld>(k + 1, INF));
ld re = INF;
for(int nr = 0; nr <= k; ++nr) { /// cati b aleg
for(int i = 0; i < n; ++i)
for(int j = 0; j <= k; ++j) DP[i][j] = INF;
///DP[i][j] : 0...i alegand j A-uri
ld fact = 1. / ld(nr + 1);
if(nr)
DP[0][0] = B[0];
else DP[0][0] = 0.;
DP[0][1] = A[0] * fact;
for(int i = 0; i + 1 < n; ++i) {
for(int j = 0; j <= min(i + 1, k - nr); ++j) {
int curB = i + 1 - j;
if(curB >= nr) {
DP[i + 1][j] = min(DP[i + 1][j], DP[i][j]); /// nu aleg nimic
}
///aleg A
if(j + 1 <= k)
DP[i + 1][j + 1] = min(DP[i + 1][j + 1], DP[i][j] + A[i + 1] * fact);
///aleg B
if(curB < nr) {
DP[i + 1][j] = min(DP[i + 1][j], DP[i][j] + ld(B[i + 1]) / ld(curB + 1));
}
}
}
re = min(re, DP[n - 1][k - nr]);
}
cout << fixed << setprecision(10) << re << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
464 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
13 ms |
856 KB |
Output is correct |
6 |
Correct |
74 ms |
1368 KB |
Output is correct |
7 |
Correct |
274 ms |
2436 KB |
Output is correct |
8 |
Correct |
566 ms |
3420 KB |
Output is correct |
9 |
Correct |
969 ms |
4388 KB |
Output is correct |
10 |
Correct |
506 ms |
3216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
464 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
13 ms |
856 KB |
Output is correct |
6 |
Correct |
74 ms |
1368 KB |
Output is correct |
7 |
Correct |
274 ms |
2436 KB |
Output is correct |
8 |
Correct |
566 ms |
3420 KB |
Output is correct |
9 |
Correct |
969 ms |
4388 KB |
Output is correct |
10 |
Correct |
506 ms |
3216 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
113 ms |
1644 KB |
Output is correct |
13 |
Correct |
101 ms |
1652 KB |
Output is correct |
14 |
Correct |
107 ms |
1644 KB |
Output is correct |
15 |
Correct |
510 ms |
3216 KB |
Output is correct |
16 |
Correct |
531 ms |
3212 KB |
Output is correct |
17 |
Correct |
502 ms |
3216 KB |
Output is correct |
18 |
Correct |
999 ms |
4408 KB |
Output is correct |
19 |
Correct |
987 ms |
4392 KB |
Output is correct |
20 |
Correct |
975 ms |
4396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
504 KB |
Output is correct |
2 |
Correct |
1 ms |
456 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
448 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 |
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 |
1 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 |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
504 KB |
Output is correct |
2 |
Correct |
1 ms |
456 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
448 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 |
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 |
1 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 |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
500 KB |
Output is correct |
17 |
Correct |
1 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 |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 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 |
352 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 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 |
344 KB |
Output is correct |
36 |
Correct |
1 ms |
344 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
504 KB |
Output is correct |
2 |
Correct |
1 ms |
456 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
448 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 |
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 |
1 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 |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
500 KB |
Output is correct |
17 |
Correct |
1 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 |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 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 |
352 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 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 |
344 KB |
Output is correct |
36 |
Correct |
1 ms |
344 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
1 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 |
344 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
1 ms |
348 KB |
Output is correct |
45 |
Correct |
3 ms |
348 KB |
Output is correct |
46 |
Correct |
3 ms |
348 KB |
Output is correct |
47 |
Correct |
4 ms |
344 KB |
Output is correct |
48 |
Correct |
5 ms |
560 KB |
Output is correct |
49 |
Correct |
6 ms |
348 KB |
Output is correct |
50 |
Correct |
6 ms |
348 KB |
Output is correct |
51 |
Correct |
9 ms |
604 KB |
Output is correct |
52 |
Correct |
8 ms |
604 KB |
Output is correct |
53 |
Correct |
6 ms |
600 KB |
Output is correct |
54 |
Correct |
6 ms |
348 KB |
Output is correct |
55 |
Correct |
4 ms |
348 KB |
Output is correct |
56 |
Correct |
4 ms |
452 KB |
Output is correct |
57 |
Correct |
4 ms |
348 KB |
Output is correct |
58 |
Correct |
4 ms |
348 KB |
Output is correct |
59 |
Correct |
4 ms |
348 KB |
Output is correct |
60 |
Correct |
4 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1004 ms |
4540 KB |
Output is correct |
2 |
Correct |
1022 ms |
4392 KB |
Output is correct |
3 |
Correct |
959 ms |
4392 KB |
Output is correct |
4 |
Correct |
979 ms |
4388 KB |
Output is correct |
5 |
Correct |
972 ms |
4388 KB |
Output is correct |
6 |
Correct |
988 ms |
4392 KB |
Output is correct |
7 |
Correct |
976 ms |
4392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
464 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
13 ms |
856 KB |
Output is correct |
6 |
Correct |
74 ms |
1368 KB |
Output is correct |
7 |
Correct |
274 ms |
2436 KB |
Output is correct |
8 |
Correct |
566 ms |
3420 KB |
Output is correct |
9 |
Correct |
969 ms |
4388 KB |
Output is correct |
10 |
Correct |
506 ms |
3216 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
113 ms |
1644 KB |
Output is correct |
13 |
Correct |
101 ms |
1652 KB |
Output is correct |
14 |
Correct |
107 ms |
1644 KB |
Output is correct |
15 |
Correct |
510 ms |
3216 KB |
Output is correct |
16 |
Correct |
531 ms |
3212 KB |
Output is correct |
17 |
Correct |
502 ms |
3216 KB |
Output is correct |
18 |
Correct |
999 ms |
4408 KB |
Output is correct |
19 |
Correct |
987 ms |
4392 KB |
Output is correct |
20 |
Correct |
975 ms |
4396 KB |
Output is correct |
21 |
Correct |
1 ms |
504 KB |
Output is correct |
22 |
Correct |
1 ms |
456 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
448 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 |
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 |
1 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 |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
1 ms |
500 KB |
Output is correct |
37 |
Correct |
1 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 |
344 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
344 KB |
Output is correct |
44 |
Correct |
1 ms |
348 KB |
Output is correct |
45 |
Correct |
1 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 |
1 ms |
352 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
51 |
Correct |
1 ms |
348 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
0 ms |
344 KB |
Output is correct |
56 |
Correct |
1 ms |
344 KB |
Output is correct |
57 |
Correct |
1 ms |
348 KB |
Output is correct |
58 |
Correct |
1 ms |
348 KB |
Output is correct |
59 |
Correct |
1 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 |
344 KB |
Output is correct |
63 |
Correct |
1 ms |
348 KB |
Output is correct |
64 |
Correct |
1 ms |
348 KB |
Output is correct |
65 |
Correct |
3 ms |
348 KB |
Output is correct |
66 |
Correct |
3 ms |
348 KB |
Output is correct |
67 |
Correct |
4 ms |
344 KB |
Output is correct |
68 |
Correct |
5 ms |
560 KB |
Output is correct |
69 |
Correct |
6 ms |
348 KB |
Output is correct |
70 |
Correct |
6 ms |
348 KB |
Output is correct |
71 |
Correct |
9 ms |
604 KB |
Output is correct |
72 |
Correct |
8 ms |
604 KB |
Output is correct |
73 |
Correct |
6 ms |
600 KB |
Output is correct |
74 |
Correct |
6 ms |
348 KB |
Output is correct |
75 |
Correct |
4 ms |
348 KB |
Output is correct |
76 |
Correct |
4 ms |
452 KB |
Output is correct |
77 |
Correct |
4 ms |
348 KB |
Output is correct |
78 |
Correct |
4 ms |
348 KB |
Output is correct |
79 |
Correct |
4 ms |
348 KB |
Output is correct |
80 |
Correct |
4 ms |
348 KB |
Output is correct |
81 |
Correct |
1004 ms |
4540 KB |
Output is correct |
82 |
Correct |
1022 ms |
4392 KB |
Output is correct |
83 |
Correct |
959 ms |
4392 KB |
Output is correct |
84 |
Correct |
979 ms |
4388 KB |
Output is correct |
85 |
Correct |
972 ms |
4388 KB |
Output is correct |
86 |
Correct |
988 ms |
4392 KB |
Output is correct |
87 |
Correct |
976 ms |
4392 KB |
Output is correct |
88 |
Correct |
15 ms |
860 KB |
Output is correct |
89 |
Correct |
13 ms |
856 KB |
Output is correct |
90 |
Correct |
72 ms |
1372 KB |
Output is correct |
91 |
Correct |
71 ms |
1368 KB |
Output is correct |
92 |
Correct |
290 ms |
2432 KB |
Output is correct |
93 |
Correct |
280 ms |
2428 KB |
Output is correct |
94 |
Correct |
587 ms |
3420 KB |
Output is correct |
95 |
Correct |
571 ms |
3416 KB |
Output is correct |
96 |
Correct |
790 ms |
3932 KB |
Output is correct |
97 |
Correct |
797 ms |
4000 KB |
Output is correct |
98 |
Correct |
520 ms |
3164 KB |
Output is correct |
99 |
Correct |
517 ms |
3220 KB |
Output is correct |
100 |
Correct |
514 ms |
3216 KB |
Output is correct |
101 |
Correct |
534 ms |
3220 KB |
Output is correct |
102 |
Correct |
511 ms |
3220 KB |
Output is correct |
103 |
Correct |
520 ms |
3224 KB |
Output is correct |
104 |
Correct |
531 ms |
3004 KB |
Output is correct |
105 |
Correct |
535 ms |
3212 KB |
Output is correct |