#include <algorithm>
#include <iomanip>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
#define int long long
using pdd = pair<long double, long double>;
const long double INF = 1e18;
const int maxn = 505;
int n, k;
vector<pdd> vc;
long double dp[maxn][maxn];
long double sf[maxn][maxn]; // sf[i][j] 從 A[i~(n-1)] 選 j 個最小的數字
void build_sf() {
for (int i = 1; i < maxn; i++) {
fill(sf[i] + 1, sf[i] + maxn, INF);
}
for (int i = n - 1; i >= 0; i--) {
vector<long double> cur;
for (int j = i; j < n; j++) {
cur.push_back(vc[j].first);
}
sort(cur.begin(), cur.end());
sf[i][0] = 0;
for (int j = 1; j <= k; j++) {
if (j > (int)(cur.size()))
break;
else
sf[i][j] = sf[i][j - 1] + cur[j - 1];
}
}
}
long double solve(const int t) {
for (int i = 0; i < n; i++) {
fill(dp[i], dp[i] + (t + 1), INF);
}
for (int i = 0; i < n; i++) {
if (i == 0) {
dp[i][0] = vc[i].first / (t + 1.0);
dp[i][1] = vc[i].second;
continue;
}
for (int j = 0; j <= t; j++) {
if (j == 0) {
dp[i][0] = dp[i - 1][0] + vc[i].first / (t + 1.0);
} else {
long double x = dp[i - 1][j] + vc[i].first / (t + 1.0);
long double y = dp[i - 1][j - 1] + vc[i].second * 1.0 / j;
dp[i][j] = min(x, y);
}
}
}
// if (k == n) return dp[n - 1][t];
long double res = sf[0][k];
for (int i = 0; i < n; i++) {
if (k - (i+1) >= 0) {
res = min(res, dp[i][t] + sf[i + 1][k - (i+1)] / (t + 1));
}
}
return res;
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(15);
cin >> n >> k;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
if (y == -1) {
vc.push_back({x, INF});
} else {
vc.push_back({x, y});
}
}
sort(vc.begin(), vc.end(),
[](pdd a, pdd b) { return a.second < b.second; });
build_sf();
long double res = sf[0][k];
for (int t = 1; t <= k; t++) {
res = min(res, solve(t));
}
cout << res << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4308 KB |
Output is correct |
2 |
Correct |
3 ms |
4308 KB |
Output is correct |
3 |
Correct |
3 ms |
4308 KB |
Output is correct |
4 |
Correct |
3 ms |
4308 KB |
Output is correct |
5 |
Correct |
24 ms |
6612 KB |
Output is correct |
6 |
Correct |
71 ms |
7288 KB |
Output is correct |
7 |
Correct |
230 ms |
8240 KB |
Output is correct |
8 |
Correct |
526 ms |
8292 KB |
Output is correct |
9 |
Correct |
893 ms |
8292 KB |
Output is correct |
10 |
Correct |
443 ms |
8284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4308 KB |
Output is correct |
2 |
Correct |
3 ms |
4308 KB |
Output is correct |
3 |
Correct |
3 ms |
4308 KB |
Output is correct |
4 |
Correct |
3 ms |
4308 KB |
Output is correct |
5 |
Correct |
24 ms |
6612 KB |
Output is correct |
6 |
Correct |
71 ms |
7288 KB |
Output is correct |
7 |
Correct |
230 ms |
8240 KB |
Output is correct |
8 |
Correct |
526 ms |
8292 KB |
Output is correct |
9 |
Correct |
893 ms |
8292 KB |
Output is correct |
10 |
Correct |
443 ms |
8284 KB |
Output is correct |
11 |
Correct |
3 ms |
4308 KB |
Output is correct |
12 |
Correct |
95 ms |
7468 KB |
Output is correct |
13 |
Correct |
102 ms |
7472 KB |
Output is correct |
14 |
Correct |
101 ms |
7380 KB |
Output is correct |
15 |
Correct |
476 ms |
8412 KB |
Output is correct |
16 |
Correct |
450 ms |
8288 KB |
Output is correct |
17 |
Correct |
455 ms |
8304 KB |
Output is correct |
18 |
Correct |
912 ms |
8292 KB |
Output is correct |
19 |
Correct |
890 ms |
8296 KB |
Output is correct |
20 |
Correct |
935 ms |
8288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4308 KB |
Output is correct |
2 |
Correct |
4 ms |
4308 KB |
Output is correct |
3 |
Correct |
4 ms |
4308 KB |
Output is correct |
4 |
Correct |
4 ms |
4308 KB |
Output is correct |
5 |
Correct |
4 ms |
4308 KB |
Output is correct |
6 |
Correct |
4 ms |
4308 KB |
Output is correct |
7 |
Correct |
5 ms |
4308 KB |
Output is correct |
8 |
Correct |
4 ms |
4308 KB |
Output is correct |
9 |
Correct |
4 ms |
4308 KB |
Output is correct |
10 |
Correct |
4 ms |
4308 KB |
Output is correct |
11 |
Correct |
4 ms |
4308 KB |
Output is correct |
12 |
Correct |
3 ms |
4308 KB |
Output is correct |
13 |
Correct |
4 ms |
4300 KB |
Output is correct |
14 |
Correct |
4 ms |
4308 KB |
Output is correct |
15 |
Correct |
4 ms |
4300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4308 KB |
Output is correct |
2 |
Correct |
4 ms |
4308 KB |
Output is correct |
3 |
Correct |
4 ms |
4308 KB |
Output is correct |
4 |
Correct |
4 ms |
4308 KB |
Output is correct |
5 |
Correct |
4 ms |
4308 KB |
Output is correct |
6 |
Correct |
4 ms |
4308 KB |
Output is correct |
7 |
Correct |
5 ms |
4308 KB |
Output is correct |
8 |
Correct |
4 ms |
4308 KB |
Output is correct |
9 |
Correct |
4 ms |
4308 KB |
Output is correct |
10 |
Correct |
4 ms |
4308 KB |
Output is correct |
11 |
Correct |
4 ms |
4308 KB |
Output is correct |
12 |
Correct |
3 ms |
4308 KB |
Output is correct |
13 |
Correct |
4 ms |
4300 KB |
Output is correct |
14 |
Correct |
4 ms |
4308 KB |
Output is correct |
15 |
Correct |
4 ms |
4300 KB |
Output is correct |
16 |
Correct |
4 ms |
4308 KB |
Output is correct |
17 |
Correct |
3 ms |
4308 KB |
Output is correct |
18 |
Correct |
4 ms |
4308 KB |
Output is correct |
19 |
Correct |
4 ms |
4300 KB |
Output is correct |
20 |
Correct |
3 ms |
4308 KB |
Output is correct |
21 |
Correct |
4 ms |
4308 KB |
Output is correct |
22 |
Correct |
4 ms |
4308 KB |
Output is correct |
23 |
Correct |
4 ms |
4304 KB |
Output is correct |
24 |
Correct |
4 ms |
4312 KB |
Output is correct |
25 |
Correct |
4 ms |
4312 KB |
Output is correct |
26 |
Correct |
4 ms |
4312 KB |
Output is correct |
27 |
Correct |
4 ms |
4312 KB |
Output is correct |
28 |
Correct |
4 ms |
4312 KB |
Output is correct |
29 |
Correct |
5 ms |
4440 KB |
Output is correct |
30 |
Correct |
4 ms |
4312 KB |
Output is correct |
31 |
Correct |
3 ms |
4308 KB |
Output is correct |
32 |
Correct |
4 ms |
4308 KB |
Output is correct |
33 |
Correct |
4 ms |
4296 KB |
Output is correct |
34 |
Correct |
4 ms |
4308 KB |
Output is correct |
35 |
Correct |
4 ms |
4308 KB |
Output is correct |
36 |
Correct |
4 ms |
4300 KB |
Output is correct |
37 |
Correct |
4 ms |
4308 KB |
Output is correct |
38 |
Correct |
3 ms |
4304 KB |
Output is correct |
39 |
Correct |
4 ms |
4308 KB |
Output is correct |
40 |
Correct |
4 ms |
4308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4308 KB |
Output is correct |
2 |
Correct |
4 ms |
4308 KB |
Output is correct |
3 |
Correct |
4 ms |
4308 KB |
Output is correct |
4 |
Correct |
4 ms |
4308 KB |
Output is correct |
5 |
Correct |
4 ms |
4308 KB |
Output is correct |
6 |
Correct |
4 ms |
4308 KB |
Output is correct |
7 |
Correct |
5 ms |
4308 KB |
Output is correct |
8 |
Correct |
4 ms |
4308 KB |
Output is correct |
9 |
Correct |
4 ms |
4308 KB |
Output is correct |
10 |
Correct |
4 ms |
4308 KB |
Output is correct |
11 |
Correct |
4 ms |
4308 KB |
Output is correct |
12 |
Correct |
3 ms |
4308 KB |
Output is correct |
13 |
Correct |
4 ms |
4300 KB |
Output is correct |
14 |
Correct |
4 ms |
4308 KB |
Output is correct |
15 |
Correct |
4 ms |
4300 KB |
Output is correct |
16 |
Correct |
4 ms |
4308 KB |
Output is correct |
17 |
Correct |
3 ms |
4308 KB |
Output is correct |
18 |
Correct |
4 ms |
4308 KB |
Output is correct |
19 |
Correct |
4 ms |
4300 KB |
Output is correct |
20 |
Correct |
3 ms |
4308 KB |
Output is correct |
21 |
Correct |
4 ms |
4308 KB |
Output is correct |
22 |
Correct |
4 ms |
4308 KB |
Output is correct |
23 |
Correct |
4 ms |
4304 KB |
Output is correct |
24 |
Correct |
4 ms |
4312 KB |
Output is correct |
25 |
Correct |
4 ms |
4312 KB |
Output is correct |
26 |
Correct |
4 ms |
4312 KB |
Output is correct |
27 |
Correct |
4 ms |
4312 KB |
Output is correct |
28 |
Correct |
4 ms |
4312 KB |
Output is correct |
29 |
Correct |
5 ms |
4440 KB |
Output is correct |
30 |
Correct |
4 ms |
4312 KB |
Output is correct |
31 |
Correct |
3 ms |
4308 KB |
Output is correct |
32 |
Correct |
4 ms |
4308 KB |
Output is correct |
33 |
Correct |
4 ms |
4296 KB |
Output is correct |
34 |
Correct |
4 ms |
4308 KB |
Output is correct |
35 |
Correct |
4 ms |
4308 KB |
Output is correct |
36 |
Correct |
4 ms |
4300 KB |
Output is correct |
37 |
Correct |
4 ms |
4308 KB |
Output is correct |
38 |
Correct |
3 ms |
4304 KB |
Output is correct |
39 |
Correct |
4 ms |
4308 KB |
Output is correct |
40 |
Correct |
4 ms |
4308 KB |
Output is correct |
41 |
Correct |
4 ms |
4704 KB |
Output is correct |
42 |
Correct |
5 ms |
4772 KB |
Output is correct |
43 |
Correct |
5 ms |
4704 KB |
Output is correct |
44 |
Correct |
5 ms |
4700 KB |
Output is correct |
45 |
Correct |
6 ms |
4704 KB |
Output is correct |
46 |
Correct |
6 ms |
4780 KB |
Output is correct |
47 |
Correct |
8 ms |
4820 KB |
Output is correct |
48 |
Correct |
8 ms |
4832 KB |
Output is correct |
49 |
Correct |
9 ms |
4832 KB |
Output is correct |
50 |
Correct |
10 ms |
4852 KB |
Output is correct |
51 |
Correct |
12 ms |
4832 KB |
Output is correct |
52 |
Correct |
11 ms |
4824 KB |
Output is correct |
53 |
Correct |
7 ms |
4836 KB |
Output is correct |
54 |
Correct |
8 ms |
4816 KB |
Output is correct |
55 |
Correct |
7 ms |
4820 KB |
Output is correct |
56 |
Correct |
7 ms |
4820 KB |
Output is correct |
57 |
Correct |
7 ms |
4788 KB |
Output is correct |
58 |
Correct |
7 ms |
4828 KB |
Output is correct |
59 |
Correct |
7 ms |
4820 KB |
Output is correct |
60 |
Correct |
11 ms |
4812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
990 ms |
8332 KB |
Output is correct |
2 |
Correct |
953 ms |
8288 KB |
Output is correct |
3 |
Correct |
892 ms |
8268 KB |
Output is correct |
4 |
Correct |
896 ms |
8356 KB |
Output is correct |
5 |
Correct |
898 ms |
8292 KB |
Output is correct |
6 |
Correct |
878 ms |
8288 KB |
Output is correct |
7 |
Correct |
882 ms |
8260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4308 KB |
Output is correct |
2 |
Correct |
3 ms |
4308 KB |
Output is correct |
3 |
Correct |
3 ms |
4308 KB |
Output is correct |
4 |
Correct |
3 ms |
4308 KB |
Output is correct |
5 |
Correct |
24 ms |
6612 KB |
Output is correct |
6 |
Correct |
71 ms |
7288 KB |
Output is correct |
7 |
Correct |
230 ms |
8240 KB |
Output is correct |
8 |
Correct |
526 ms |
8292 KB |
Output is correct |
9 |
Correct |
893 ms |
8292 KB |
Output is correct |
10 |
Correct |
443 ms |
8284 KB |
Output is correct |
11 |
Correct |
3 ms |
4308 KB |
Output is correct |
12 |
Correct |
95 ms |
7468 KB |
Output is correct |
13 |
Correct |
102 ms |
7472 KB |
Output is correct |
14 |
Correct |
101 ms |
7380 KB |
Output is correct |
15 |
Correct |
476 ms |
8412 KB |
Output is correct |
16 |
Correct |
450 ms |
8288 KB |
Output is correct |
17 |
Correct |
455 ms |
8304 KB |
Output is correct |
18 |
Correct |
912 ms |
8292 KB |
Output is correct |
19 |
Correct |
890 ms |
8296 KB |
Output is correct |
20 |
Correct |
935 ms |
8288 KB |
Output is correct |
21 |
Correct |
4 ms |
4308 KB |
Output is correct |
22 |
Correct |
4 ms |
4308 KB |
Output is correct |
23 |
Correct |
4 ms |
4308 KB |
Output is correct |
24 |
Correct |
4 ms |
4308 KB |
Output is correct |
25 |
Correct |
4 ms |
4308 KB |
Output is correct |
26 |
Correct |
4 ms |
4308 KB |
Output is correct |
27 |
Correct |
5 ms |
4308 KB |
Output is correct |
28 |
Correct |
4 ms |
4308 KB |
Output is correct |
29 |
Correct |
4 ms |
4308 KB |
Output is correct |
30 |
Correct |
4 ms |
4308 KB |
Output is correct |
31 |
Correct |
4 ms |
4308 KB |
Output is correct |
32 |
Correct |
3 ms |
4308 KB |
Output is correct |
33 |
Correct |
4 ms |
4300 KB |
Output is correct |
34 |
Correct |
4 ms |
4308 KB |
Output is correct |
35 |
Correct |
4 ms |
4300 KB |
Output is correct |
36 |
Correct |
4 ms |
4308 KB |
Output is correct |
37 |
Correct |
3 ms |
4308 KB |
Output is correct |
38 |
Correct |
4 ms |
4308 KB |
Output is correct |
39 |
Correct |
4 ms |
4300 KB |
Output is correct |
40 |
Correct |
3 ms |
4308 KB |
Output is correct |
41 |
Correct |
4 ms |
4308 KB |
Output is correct |
42 |
Correct |
4 ms |
4308 KB |
Output is correct |
43 |
Correct |
4 ms |
4304 KB |
Output is correct |
44 |
Correct |
4 ms |
4312 KB |
Output is correct |
45 |
Correct |
4 ms |
4312 KB |
Output is correct |
46 |
Correct |
4 ms |
4312 KB |
Output is correct |
47 |
Correct |
4 ms |
4312 KB |
Output is correct |
48 |
Correct |
4 ms |
4312 KB |
Output is correct |
49 |
Correct |
5 ms |
4440 KB |
Output is correct |
50 |
Correct |
4 ms |
4312 KB |
Output is correct |
51 |
Correct |
3 ms |
4308 KB |
Output is correct |
52 |
Correct |
4 ms |
4308 KB |
Output is correct |
53 |
Correct |
4 ms |
4296 KB |
Output is correct |
54 |
Correct |
4 ms |
4308 KB |
Output is correct |
55 |
Correct |
4 ms |
4308 KB |
Output is correct |
56 |
Correct |
4 ms |
4300 KB |
Output is correct |
57 |
Correct |
4 ms |
4308 KB |
Output is correct |
58 |
Correct |
3 ms |
4304 KB |
Output is correct |
59 |
Correct |
4 ms |
4308 KB |
Output is correct |
60 |
Correct |
4 ms |
4308 KB |
Output is correct |
61 |
Correct |
4 ms |
4704 KB |
Output is correct |
62 |
Correct |
5 ms |
4772 KB |
Output is correct |
63 |
Correct |
5 ms |
4704 KB |
Output is correct |
64 |
Correct |
5 ms |
4700 KB |
Output is correct |
65 |
Correct |
6 ms |
4704 KB |
Output is correct |
66 |
Correct |
6 ms |
4780 KB |
Output is correct |
67 |
Correct |
8 ms |
4820 KB |
Output is correct |
68 |
Correct |
8 ms |
4832 KB |
Output is correct |
69 |
Correct |
9 ms |
4832 KB |
Output is correct |
70 |
Correct |
10 ms |
4852 KB |
Output is correct |
71 |
Correct |
12 ms |
4832 KB |
Output is correct |
72 |
Correct |
11 ms |
4824 KB |
Output is correct |
73 |
Correct |
7 ms |
4836 KB |
Output is correct |
74 |
Correct |
8 ms |
4816 KB |
Output is correct |
75 |
Correct |
7 ms |
4820 KB |
Output is correct |
76 |
Correct |
7 ms |
4820 KB |
Output is correct |
77 |
Correct |
7 ms |
4788 KB |
Output is correct |
78 |
Correct |
7 ms |
4828 KB |
Output is correct |
79 |
Correct |
7 ms |
4820 KB |
Output is correct |
80 |
Correct |
11 ms |
4812 KB |
Output is correct |
81 |
Correct |
990 ms |
8332 KB |
Output is correct |
82 |
Correct |
953 ms |
8288 KB |
Output is correct |
83 |
Correct |
892 ms |
8268 KB |
Output is correct |
84 |
Correct |
896 ms |
8356 KB |
Output is correct |
85 |
Correct |
898 ms |
8292 KB |
Output is correct |
86 |
Correct |
878 ms |
8288 KB |
Output is correct |
87 |
Correct |
882 ms |
8260 KB |
Output is correct |
88 |
Correct |
24 ms |
6668 KB |
Output is correct |
89 |
Correct |
23 ms |
6720 KB |
Output is correct |
90 |
Correct |
81 ms |
7280 KB |
Output is correct |
91 |
Correct |
72 ms |
7292 KB |
Output is correct |
92 |
Correct |
231 ms |
8264 KB |
Output is correct |
93 |
Correct |
271 ms |
8276 KB |
Output is correct |
94 |
Correct |
501 ms |
8268 KB |
Output is correct |
95 |
Correct |
518 ms |
8396 KB |
Output is correct |
96 |
Correct |
723 ms |
8268 KB |
Output is correct |
97 |
Correct |
741 ms |
8396 KB |
Output is correct |
98 |
Correct |
441 ms |
8212 KB |
Output is correct |
99 |
Correct |
485 ms |
8320 KB |
Output is correct |
100 |
Correct |
484 ms |
8292 KB |
Output is correct |
101 |
Correct |
443 ms |
8272 KB |
Output is correct |
102 |
Correct |
438 ms |
8300 KB |
Output is correct |
103 |
Correct |
450 ms |
8256 KB |
Output is correct |
104 |
Correct |
452 ms |
8268 KB |
Output is correct |
105 |
Correct |
452 ms |
8192 KB |
Output is correct |