#include <bits/stdc++.h>
using namespace std;
constexpr int maxn = 101, inf = 1e9 + 7;
double dp[maxn][maxn][maxn][maxn];
void solve() {
int n, k;
cin >> n >> k;
vector<double> a(n), b(n);
vector<pair<double, int>> s_b;
for (int i = 0; i < n; ++i) {
cin >> a[i] >> b[i];
if (b[i] > 0) {
s_b.emplace_back(b[i], i);
} else {
s_b.emplace_back(inf, i);
}
}
sort(s_b.begin(), s_b.end());
for (int i = 0; i <= n; ++i) {
for (int cnt_all = 0; cnt_all < k; ++cnt_all) {
for (int cnt_nw = 0; cnt_nw <= i && cnt_nw <= cnt_all; ++cnt_nw) {
for (int cnt_used = 0; cnt_used <= k; ++cnt_used) {
dp[i][cnt_all][cnt_nw][cnt_used] = inf;
}
}
}
}
for (int cnt_all = 0; cnt_all < k; ++cnt_all) {
dp[0][cnt_all][0][0] = 0;
}
double ans = inf;
for (int i = 0; i < n; ++i) {
for (int cnt_all = 0; cnt_all < k; ++cnt_all) {
for (int cnt_nw = 0; cnt_nw <= i && cnt_nw <= cnt_all; ++cnt_nw) {
for (int cnt_used = 0; cnt_used < k; ++cnt_used) {
if (s_b[i].first < 10000 && cnt_nw < cnt_all) {
dp[i + 1][cnt_all][cnt_nw + 1][cnt_used + 1] = min(dp[i + 1][cnt_all][cnt_nw + 1][cnt_used + 1], dp[i][cnt_all][cnt_nw][cnt_used] + s_b[i].first / (double)(cnt_nw + 1));
if (cnt_used + 1 == k && cnt_nw + 1 == cnt_all) {
ans = min(ans, dp[i + 1][cnt_all][cnt_nw + 1][cnt_used + 1]);
}
}
dp[i + 1][cnt_all][cnt_nw][cnt_used + 1] = min(dp[i + 1][cnt_all][cnt_nw][cnt_used + 1], dp[i][cnt_all][cnt_nw][cnt_used] + a[s_b[i].second] / (double)(cnt_all + 1));
if (cnt_used + 1 == k && cnt_nw == cnt_all) {
ans = min(ans, dp[i + 1][cnt_all][cnt_nw][cnt_used + 1]);
}
dp[i + 1][cnt_all][cnt_nw][cnt_used] = min(dp[i + 1][cnt_all][cnt_nw][cnt_used], dp[i][cnt_all][cnt_nw][cnt_used]);
}
}
}
}
cout << ans << '\n';
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.precision(25);
cout << fixed;
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Runtime error |
307 ms |
534264 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Runtime error |
307 ms |
534264 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14684 KB |
Output is correct |
2 |
Correct |
3 ms |
14684 KB |
Output is correct |
3 |
Correct |
2 ms |
14804 KB |
Output is correct |
4 |
Correct |
2 ms |
16732 KB |
Output is correct |
5 |
Correct |
2 ms |
18780 KB |
Output is correct |
6 |
Correct |
3 ms |
18780 KB |
Output is correct |
7 |
Correct |
2 ms |
20828 KB |
Output is correct |
8 |
Correct |
2 ms |
18780 KB |
Output is correct |
9 |
Correct |
2 ms |
18780 KB |
Output is correct |
10 |
Correct |
3 ms |
18776 KB |
Output is correct |
11 |
Correct |
2 ms |
18776 KB |
Output is correct |
12 |
Correct |
2 ms |
18776 KB |
Output is correct |
13 |
Correct |
3 ms |
18780 KB |
Output is correct |
14 |
Correct |
2 ms |
14684 KB |
Output is correct |
15 |
Correct |
2 ms |
20828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14684 KB |
Output is correct |
2 |
Correct |
3 ms |
14684 KB |
Output is correct |
3 |
Correct |
2 ms |
14804 KB |
Output is correct |
4 |
Correct |
2 ms |
16732 KB |
Output is correct |
5 |
Correct |
2 ms |
18780 KB |
Output is correct |
6 |
Correct |
3 ms |
18780 KB |
Output is correct |
7 |
Correct |
2 ms |
20828 KB |
Output is correct |
8 |
Correct |
2 ms |
18780 KB |
Output is correct |
9 |
Correct |
2 ms |
18780 KB |
Output is correct |
10 |
Correct |
3 ms |
18776 KB |
Output is correct |
11 |
Correct |
2 ms |
18776 KB |
Output is correct |
12 |
Correct |
2 ms |
18776 KB |
Output is correct |
13 |
Correct |
3 ms |
18780 KB |
Output is correct |
14 |
Correct |
2 ms |
14684 KB |
Output is correct |
15 |
Correct |
2 ms |
20828 KB |
Output is correct |
16 |
Correct |
5 ms |
43356 KB |
Output is correct |
17 |
Correct |
6 ms |
57896 KB |
Output is correct |
18 |
Correct |
6 ms |
57688 KB |
Output is correct |
19 |
Correct |
7 ms |
65884 KB |
Output is correct |
20 |
Correct |
7 ms |
65884 KB |
Output is correct |
21 |
Correct |
7 ms |
65884 KB |
Output is correct |
22 |
Correct |
8 ms |
70236 KB |
Output is correct |
23 |
Correct |
7 ms |
70236 KB |
Output is correct |
24 |
Correct |
8 ms |
70236 KB |
Output is correct |
25 |
Correct |
8 ms |
76376 KB |
Output is correct |
26 |
Correct |
8 ms |
76380 KB |
Output is correct |
27 |
Correct |
13 ms |
66136 KB |
Output is correct |
28 |
Correct |
7 ms |
70236 KB |
Output is correct |
29 |
Correct |
7 ms |
66016 KB |
Output is correct |
30 |
Correct |
8 ms |
70236 KB |
Output is correct |
31 |
Correct |
8 ms |
66140 KB |
Output is correct |
32 |
Correct |
7 ms |
70232 KB |
Output is correct |
33 |
Correct |
9 ms |
65880 KB |
Output is correct |
34 |
Correct |
8 ms |
66140 KB |
Output is correct |
35 |
Correct |
7 ms |
70236 KB |
Output is correct |
36 |
Correct |
7 ms |
65884 KB |
Output is correct |
37 |
Correct |
7 ms |
70196 KB |
Output is correct |
38 |
Correct |
7 ms |
65884 KB |
Output is correct |
39 |
Correct |
8 ms |
70232 KB |
Output is correct |
40 |
Correct |
7 ms |
66044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14684 KB |
Output is correct |
2 |
Correct |
3 ms |
14684 KB |
Output is correct |
3 |
Correct |
2 ms |
14804 KB |
Output is correct |
4 |
Correct |
2 ms |
16732 KB |
Output is correct |
5 |
Correct |
2 ms |
18780 KB |
Output is correct |
6 |
Correct |
3 ms |
18780 KB |
Output is correct |
7 |
Correct |
2 ms |
20828 KB |
Output is correct |
8 |
Correct |
2 ms |
18780 KB |
Output is correct |
9 |
Correct |
2 ms |
18780 KB |
Output is correct |
10 |
Correct |
3 ms |
18776 KB |
Output is correct |
11 |
Correct |
2 ms |
18776 KB |
Output is correct |
12 |
Correct |
2 ms |
18776 KB |
Output is correct |
13 |
Correct |
3 ms |
18780 KB |
Output is correct |
14 |
Correct |
2 ms |
14684 KB |
Output is correct |
15 |
Correct |
2 ms |
20828 KB |
Output is correct |
16 |
Correct |
5 ms |
43356 KB |
Output is correct |
17 |
Correct |
6 ms |
57896 KB |
Output is correct |
18 |
Correct |
6 ms |
57688 KB |
Output is correct |
19 |
Correct |
7 ms |
65884 KB |
Output is correct |
20 |
Correct |
7 ms |
65884 KB |
Output is correct |
21 |
Correct |
7 ms |
65884 KB |
Output is correct |
22 |
Correct |
8 ms |
70236 KB |
Output is correct |
23 |
Correct |
7 ms |
70236 KB |
Output is correct |
24 |
Correct |
8 ms |
70236 KB |
Output is correct |
25 |
Correct |
8 ms |
76376 KB |
Output is correct |
26 |
Correct |
8 ms |
76380 KB |
Output is correct |
27 |
Correct |
13 ms |
66136 KB |
Output is correct |
28 |
Correct |
7 ms |
70236 KB |
Output is correct |
29 |
Correct |
7 ms |
66016 KB |
Output is correct |
30 |
Correct |
8 ms |
70236 KB |
Output is correct |
31 |
Correct |
8 ms |
66140 KB |
Output is correct |
32 |
Correct |
7 ms |
70232 KB |
Output is correct |
33 |
Correct |
9 ms |
65880 KB |
Output is correct |
34 |
Correct |
8 ms |
66140 KB |
Output is correct |
35 |
Correct |
7 ms |
70236 KB |
Output is correct |
36 |
Correct |
7 ms |
65884 KB |
Output is correct |
37 |
Correct |
7 ms |
70196 KB |
Output is correct |
38 |
Correct |
7 ms |
65884 KB |
Output is correct |
39 |
Correct |
8 ms |
70232 KB |
Output is correct |
40 |
Correct |
7 ms |
66044 KB |
Output is correct |
41 |
Correct |
36 ms |
320348 KB |
Output is correct |
42 |
Correct |
32 ms |
320344 KB |
Output is correct |
43 |
Correct |
50 ms |
441424 KB |
Output is correct |
44 |
Correct |
52 ms |
441592 KB |
Output is correct |
45 |
Correct |
83 ms |
528464 KB |
Output is correct |
46 |
Correct |
79 ms |
528464 KB |
Output is correct |
47 |
Correct |
117 ms |
567636 KB |
Output is correct |
48 |
Correct |
113 ms |
567844 KB |
Output is correct |
49 |
Correct |
176 ms |
619436 KB |
Output is correct |
50 |
Correct |
161 ms |
650068 KB |
Output is correct |
51 |
Correct |
235 ms |
702036 KB |
Output is correct |
52 |
Correct |
213 ms |
703316 KB |
Output is correct |
53 |
Correct |
113 ms |
621008 KB |
Output is correct |
54 |
Correct |
114 ms |
622048 KB |
Output is correct |
55 |
Correct |
113 ms |
647288 KB |
Output is correct |
56 |
Correct |
113 ms |
647348 KB |
Output is correct |
57 |
Correct |
113 ms |
648968 KB |
Output is correct |
58 |
Correct |
114 ms |
648820 KB |
Output is correct |
59 |
Correct |
114 ms |
647240 KB |
Output is correct |
60 |
Correct |
111 ms |
645172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3121 ms |
1048576 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Runtime error |
307 ms |
534264 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |