#include "bits/stdc++.h"
using namespace std;
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
cout << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
while (l != r) cout << *l << " \n"[++l == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
return o >> a.first >> a.second;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
return o << '(' << a.first << ", " << a.second << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
bool is = false;
for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
return o << '}';
}
#ifdef local
#define test(args...) abc("[" + string(#args) + "]", args)
#else
#define test(args...) void(0)
#endif
using ll = long long;
vector<pair<int, int>> v;
int goal, n, k;
long double dp[505][505];
long double solve(int node, int ctcollab) {
if (dp[node][ctcollab] != -1) return dp[node][ctcollab];
if (node == n + 1) return 1e9;
int ctnorm = node - ctcollab;
if (ctcollab == goal) {
vector<pair<int, int>> cur;
for (int i = node; i < n; i++) {
cur.emplace_back(v[i]);
}
sort(cur.begin(), cur.end());
long double ct = 0;
for (int i = 0; i < k - node; i++) {
ct += ((long double) cur[i].first) / (ctcollab + 1);
}
return dp[node][ctcollab] = ct;
}
long double ans = solve(node + 1, ctcollab + 1) + ((long double) v[node].second) / (ctcollab + 1);
if (ctnorm + ctcollab < k) {
ans = min(ans, solve(node + 1, ctcollab) + ((long double) v[node].first) / (goal + 1));
}
// cout << ans << endl;
return dp[node][ctcollab] = ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// freopen("", "r", stdin);
// freopen("", "w", stdout);
cin >> n >> k;
for (int i = 0; i < n; i++) {
int a, b; cin >> a >> b;
if (b == -1) b = 1e9;
v.emplace_back(a, b);
}
sort(v.begin(), v.end(), [](pair<int, int> a, pair<int, int> b) {
return a.second < b.second;
});
long double ans = 1e18;
for (int i = 0; i < k; i++) {
if (i >= 1 && v[i-1].second == 1e9) break;
goal = i;
fill(&dp[0][0], &dp[0][0] + sizeof(dp) / sizeof(dp[0][0]), -1);
long double res = solve(0, 0);
ans = min(ans, res);
}
cout << fixed << setprecision(10) << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4308 KB |
Output is correct |
2 |
Correct |
2 ms |
4308 KB |
Output is correct |
3 |
Correct |
2 ms |
4308 KB |
Output is correct |
4 |
Correct |
2 ms |
4308 KB |
Output is correct |
5 |
Correct |
2 ms |
4308 KB |
Output is correct |
6 |
Correct |
2 ms |
4308 KB |
Output is correct |
7 |
Correct |
2 ms |
4308 KB |
Output is correct |
8 |
Correct |
2 ms |
4308 KB |
Output is correct |
9 |
Correct |
2 ms |
4308 KB |
Output is correct |
10 |
Correct |
3 ms |
4308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4308 KB |
Output is correct |
2 |
Correct |
2 ms |
4308 KB |
Output is correct |
3 |
Correct |
2 ms |
4308 KB |
Output is correct |
4 |
Correct |
2 ms |
4308 KB |
Output is correct |
5 |
Correct |
2 ms |
4308 KB |
Output is correct |
6 |
Correct |
2 ms |
4308 KB |
Output is correct |
7 |
Correct |
2 ms |
4308 KB |
Output is correct |
8 |
Correct |
2 ms |
4308 KB |
Output is correct |
9 |
Correct |
2 ms |
4308 KB |
Output is correct |
10 |
Correct |
3 ms |
4308 KB |
Output is correct |
11 |
Correct |
2 ms |
4308 KB |
Output is correct |
12 |
Correct |
256 ms |
4464 KB |
Output is correct |
13 |
Correct |
395 ms |
4344 KB |
Output is correct |
14 |
Correct |
306 ms |
4428 KB |
Output is correct |
15 |
Correct |
996 ms |
4480 KB |
Output is correct |
16 |
Correct |
1278 ms |
4356 KB |
Output is correct |
17 |
Correct |
507 ms |
4364 KB |
Output is correct |
18 |
Correct |
1493 ms |
4368 KB |
Output is correct |
19 |
Correct |
1370 ms |
4364 KB |
Output is correct |
20 |
Correct |
500 ms |
4428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4308 KB |
Output is correct |
2 |
Correct |
4 ms |
4308 KB |
Output is correct |
3 |
Correct |
3 ms |
4308 KB |
Output is correct |
4 |
Correct |
4 ms |
4308 KB |
Output is correct |
5 |
Correct |
5 ms |
4308 KB |
Output is correct |
6 |
Correct |
5 ms |
4308 KB |
Output is correct |
7 |
Correct |
6 ms |
4308 KB |
Output is correct |
8 |
Correct |
4 ms |
4308 KB |
Output is correct |
9 |
Correct |
5 ms |
4180 KB |
Output is correct |
10 |
Correct |
4 ms |
4308 KB |
Output is correct |
11 |
Correct |
4 ms |
4308 KB |
Output is correct |
12 |
Correct |
4 ms |
4308 KB |
Output is correct |
13 |
Correct |
4 ms |
4308 KB |
Output is correct |
14 |
Correct |
4 ms |
4180 KB |
Output is correct |
15 |
Correct |
5 ms |
4308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4308 KB |
Output is correct |
2 |
Correct |
4 ms |
4308 KB |
Output is correct |
3 |
Correct |
3 ms |
4308 KB |
Output is correct |
4 |
Correct |
4 ms |
4308 KB |
Output is correct |
5 |
Correct |
5 ms |
4308 KB |
Output is correct |
6 |
Correct |
5 ms |
4308 KB |
Output is correct |
7 |
Correct |
6 ms |
4308 KB |
Output is correct |
8 |
Correct |
4 ms |
4308 KB |
Output is correct |
9 |
Correct |
5 ms |
4180 KB |
Output is correct |
10 |
Correct |
4 ms |
4308 KB |
Output is correct |
11 |
Correct |
4 ms |
4308 KB |
Output is correct |
12 |
Correct |
4 ms |
4308 KB |
Output is correct |
13 |
Correct |
4 ms |
4308 KB |
Output is correct |
14 |
Correct |
4 ms |
4180 KB |
Output is correct |
15 |
Correct |
5 ms |
4308 KB |
Output is correct |
16 |
Correct |
4 ms |
4296 KB |
Output is correct |
17 |
Correct |
6 ms |
4248 KB |
Output is correct |
18 |
Correct |
6 ms |
4308 KB |
Output is correct |
19 |
Correct |
13 ms |
4308 KB |
Output is correct |
20 |
Correct |
9 ms |
4316 KB |
Output is correct |
21 |
Correct |
9 ms |
4312 KB |
Output is correct |
22 |
Correct |
15 ms |
4296 KB |
Output is correct |
23 |
Correct |
9 ms |
4312 KB |
Output is correct |
24 |
Correct |
8 ms |
4316 KB |
Output is correct |
25 |
Correct |
16 ms |
4312 KB |
Output is correct |
26 |
Correct |
10 ms |
4308 KB |
Output is correct |
27 |
Correct |
8 ms |
4308 KB |
Output is correct |
28 |
Correct |
8 ms |
4308 KB |
Output is correct |
29 |
Correct |
8 ms |
4296 KB |
Output is correct |
30 |
Correct |
8 ms |
4300 KB |
Output is correct |
31 |
Correct |
8 ms |
4316 KB |
Output is correct |
32 |
Correct |
9 ms |
4308 KB |
Output is correct |
33 |
Correct |
8 ms |
4308 KB |
Output is correct |
34 |
Correct |
7 ms |
4316 KB |
Output is correct |
35 |
Correct |
10 ms |
4316 KB |
Output is correct |
36 |
Correct |
8 ms |
4308 KB |
Output is correct |
37 |
Correct |
8 ms |
4308 KB |
Output is correct |
38 |
Correct |
7 ms |
4308 KB |
Output is correct |
39 |
Correct |
8 ms |
4312 KB |
Output is correct |
40 |
Correct |
7 ms |
4308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4308 KB |
Output is correct |
2 |
Correct |
4 ms |
4308 KB |
Output is correct |
3 |
Correct |
3 ms |
4308 KB |
Output is correct |
4 |
Correct |
4 ms |
4308 KB |
Output is correct |
5 |
Correct |
5 ms |
4308 KB |
Output is correct |
6 |
Correct |
5 ms |
4308 KB |
Output is correct |
7 |
Correct |
6 ms |
4308 KB |
Output is correct |
8 |
Correct |
4 ms |
4308 KB |
Output is correct |
9 |
Correct |
5 ms |
4180 KB |
Output is correct |
10 |
Correct |
4 ms |
4308 KB |
Output is correct |
11 |
Correct |
4 ms |
4308 KB |
Output is correct |
12 |
Correct |
4 ms |
4308 KB |
Output is correct |
13 |
Correct |
4 ms |
4308 KB |
Output is correct |
14 |
Correct |
4 ms |
4180 KB |
Output is correct |
15 |
Correct |
5 ms |
4308 KB |
Output is correct |
16 |
Correct |
4 ms |
4296 KB |
Output is correct |
17 |
Correct |
6 ms |
4248 KB |
Output is correct |
18 |
Correct |
6 ms |
4308 KB |
Output is correct |
19 |
Correct |
13 ms |
4308 KB |
Output is correct |
20 |
Correct |
9 ms |
4316 KB |
Output is correct |
21 |
Correct |
9 ms |
4312 KB |
Output is correct |
22 |
Correct |
15 ms |
4296 KB |
Output is correct |
23 |
Correct |
9 ms |
4312 KB |
Output is correct |
24 |
Correct |
8 ms |
4316 KB |
Output is correct |
25 |
Correct |
16 ms |
4312 KB |
Output is correct |
26 |
Correct |
10 ms |
4308 KB |
Output is correct |
27 |
Correct |
8 ms |
4308 KB |
Output is correct |
28 |
Correct |
8 ms |
4308 KB |
Output is correct |
29 |
Correct |
8 ms |
4296 KB |
Output is correct |
30 |
Correct |
8 ms |
4300 KB |
Output is correct |
31 |
Correct |
8 ms |
4316 KB |
Output is correct |
32 |
Correct |
9 ms |
4308 KB |
Output is correct |
33 |
Correct |
8 ms |
4308 KB |
Output is correct |
34 |
Correct |
7 ms |
4316 KB |
Output is correct |
35 |
Correct |
10 ms |
4316 KB |
Output is correct |
36 |
Correct |
8 ms |
4308 KB |
Output is correct |
37 |
Correct |
8 ms |
4308 KB |
Output is correct |
38 |
Correct |
7 ms |
4308 KB |
Output is correct |
39 |
Correct |
8 ms |
4312 KB |
Output is correct |
40 |
Correct |
7 ms |
4308 KB |
Output is correct |
41 |
Correct |
11 ms |
4308 KB |
Output is correct |
42 |
Correct |
9 ms |
4308 KB |
Output is correct |
43 |
Correct |
17 ms |
4312 KB |
Output is correct |
44 |
Correct |
18 ms |
4308 KB |
Output is correct |
45 |
Correct |
28 ms |
4276 KB |
Output is correct |
46 |
Correct |
30 ms |
4316 KB |
Output is correct |
47 |
Correct |
36 ms |
4316 KB |
Output is correct |
48 |
Correct |
38 ms |
4324 KB |
Output is correct |
49 |
Correct |
59 ms |
4296 KB |
Output is correct |
50 |
Correct |
62 ms |
4308 KB |
Output is correct |
51 |
Correct |
64 ms |
4312 KB |
Output is correct |
52 |
Correct |
48 ms |
4320 KB |
Output is correct |
53 |
Correct |
37 ms |
4308 KB |
Output is correct |
54 |
Correct |
42 ms |
4308 KB |
Output is correct |
55 |
Correct |
37 ms |
4316 KB |
Output is correct |
56 |
Correct |
39 ms |
4324 KB |
Output is correct |
57 |
Correct |
46 ms |
4308 KB |
Output is correct |
58 |
Correct |
46 ms |
4308 KB |
Output is correct |
59 |
Correct |
34 ms |
4308 KB |
Output is correct |
60 |
Correct |
35 ms |
4304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2160 ms |
4372 KB |
Output is correct |
2 |
Correct |
2005 ms |
4372 KB |
Output is correct |
3 |
Correct |
2143 ms |
4372 KB |
Output is correct |
4 |
Correct |
2217 ms |
4368 KB |
Output is correct |
5 |
Correct |
2118 ms |
4372 KB |
Output is correct |
6 |
Correct |
2225 ms |
4376 KB |
Output is correct |
7 |
Correct |
1964 ms |
4372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4308 KB |
Output is correct |
2 |
Correct |
2 ms |
4308 KB |
Output is correct |
3 |
Correct |
2 ms |
4308 KB |
Output is correct |
4 |
Correct |
2 ms |
4308 KB |
Output is correct |
5 |
Correct |
2 ms |
4308 KB |
Output is correct |
6 |
Correct |
2 ms |
4308 KB |
Output is correct |
7 |
Correct |
2 ms |
4308 KB |
Output is correct |
8 |
Correct |
2 ms |
4308 KB |
Output is correct |
9 |
Correct |
2 ms |
4308 KB |
Output is correct |
10 |
Correct |
3 ms |
4308 KB |
Output is correct |
11 |
Correct |
2 ms |
4308 KB |
Output is correct |
12 |
Correct |
256 ms |
4464 KB |
Output is correct |
13 |
Correct |
395 ms |
4344 KB |
Output is correct |
14 |
Correct |
306 ms |
4428 KB |
Output is correct |
15 |
Correct |
996 ms |
4480 KB |
Output is correct |
16 |
Correct |
1278 ms |
4356 KB |
Output is correct |
17 |
Correct |
507 ms |
4364 KB |
Output is correct |
18 |
Correct |
1493 ms |
4368 KB |
Output is correct |
19 |
Correct |
1370 ms |
4364 KB |
Output is correct |
20 |
Correct |
500 ms |
4428 KB |
Output is correct |
21 |
Correct |
2 ms |
4308 KB |
Output is correct |
22 |
Correct |
4 ms |
4308 KB |
Output is correct |
23 |
Correct |
3 ms |
4308 KB |
Output is correct |
24 |
Correct |
4 ms |
4308 KB |
Output is correct |
25 |
Correct |
5 ms |
4308 KB |
Output is correct |
26 |
Correct |
5 ms |
4308 KB |
Output is correct |
27 |
Correct |
6 ms |
4308 KB |
Output is correct |
28 |
Correct |
4 ms |
4308 KB |
Output is correct |
29 |
Correct |
5 ms |
4180 KB |
Output is correct |
30 |
Correct |
4 ms |
4308 KB |
Output is correct |
31 |
Correct |
4 ms |
4308 KB |
Output is correct |
32 |
Correct |
4 ms |
4308 KB |
Output is correct |
33 |
Correct |
4 ms |
4308 KB |
Output is correct |
34 |
Correct |
4 ms |
4180 KB |
Output is correct |
35 |
Correct |
5 ms |
4308 KB |
Output is correct |
36 |
Correct |
4 ms |
4296 KB |
Output is correct |
37 |
Correct |
6 ms |
4248 KB |
Output is correct |
38 |
Correct |
6 ms |
4308 KB |
Output is correct |
39 |
Correct |
13 ms |
4308 KB |
Output is correct |
40 |
Correct |
9 ms |
4316 KB |
Output is correct |
41 |
Correct |
9 ms |
4312 KB |
Output is correct |
42 |
Correct |
15 ms |
4296 KB |
Output is correct |
43 |
Correct |
9 ms |
4312 KB |
Output is correct |
44 |
Correct |
8 ms |
4316 KB |
Output is correct |
45 |
Correct |
16 ms |
4312 KB |
Output is correct |
46 |
Correct |
10 ms |
4308 KB |
Output is correct |
47 |
Correct |
8 ms |
4308 KB |
Output is correct |
48 |
Correct |
8 ms |
4308 KB |
Output is correct |
49 |
Correct |
8 ms |
4296 KB |
Output is correct |
50 |
Correct |
8 ms |
4300 KB |
Output is correct |
51 |
Correct |
8 ms |
4316 KB |
Output is correct |
52 |
Correct |
9 ms |
4308 KB |
Output is correct |
53 |
Correct |
8 ms |
4308 KB |
Output is correct |
54 |
Correct |
7 ms |
4316 KB |
Output is correct |
55 |
Correct |
10 ms |
4316 KB |
Output is correct |
56 |
Correct |
8 ms |
4308 KB |
Output is correct |
57 |
Correct |
8 ms |
4308 KB |
Output is correct |
58 |
Correct |
7 ms |
4308 KB |
Output is correct |
59 |
Correct |
8 ms |
4312 KB |
Output is correct |
60 |
Correct |
7 ms |
4308 KB |
Output is correct |
61 |
Correct |
11 ms |
4308 KB |
Output is correct |
62 |
Correct |
9 ms |
4308 KB |
Output is correct |
63 |
Correct |
17 ms |
4312 KB |
Output is correct |
64 |
Correct |
18 ms |
4308 KB |
Output is correct |
65 |
Correct |
28 ms |
4276 KB |
Output is correct |
66 |
Correct |
30 ms |
4316 KB |
Output is correct |
67 |
Correct |
36 ms |
4316 KB |
Output is correct |
68 |
Correct |
38 ms |
4324 KB |
Output is correct |
69 |
Correct |
59 ms |
4296 KB |
Output is correct |
70 |
Correct |
62 ms |
4308 KB |
Output is correct |
71 |
Correct |
64 ms |
4312 KB |
Output is correct |
72 |
Correct |
48 ms |
4320 KB |
Output is correct |
73 |
Correct |
37 ms |
4308 KB |
Output is correct |
74 |
Correct |
42 ms |
4308 KB |
Output is correct |
75 |
Correct |
37 ms |
4316 KB |
Output is correct |
76 |
Correct |
39 ms |
4324 KB |
Output is correct |
77 |
Correct |
46 ms |
4308 KB |
Output is correct |
78 |
Correct |
46 ms |
4308 KB |
Output is correct |
79 |
Correct |
34 ms |
4308 KB |
Output is correct |
80 |
Correct |
35 ms |
4304 KB |
Output is correct |
81 |
Correct |
2160 ms |
4372 KB |
Output is correct |
82 |
Correct |
2005 ms |
4372 KB |
Output is correct |
83 |
Correct |
2143 ms |
4372 KB |
Output is correct |
84 |
Correct |
2217 ms |
4368 KB |
Output is correct |
85 |
Correct |
2118 ms |
4372 KB |
Output is correct |
86 |
Correct |
2225 ms |
4376 KB |
Output is correct |
87 |
Correct |
1964 ms |
4372 KB |
Output is correct |
88 |
Correct |
92 ms |
4316 KB |
Output is correct |
89 |
Correct |
80 ms |
4328 KB |
Output is correct |
90 |
Correct |
345 ms |
4332 KB |
Output is correct |
91 |
Correct |
360 ms |
4456 KB |
Output is correct |
92 |
Correct |
991 ms |
4368 KB |
Output is correct |
93 |
Correct |
1037 ms |
4608 KB |
Output is correct |
94 |
Correct |
1663 ms |
4484 KB |
Output is correct |
95 |
Correct |
1708 ms |
4372 KB |
Output is correct |
96 |
Correct |
2172 ms |
4372 KB |
Output is correct |
97 |
Correct |
2148 ms |
4376 KB |
Output is correct |
98 |
Correct |
1516 ms |
4492 KB |
Output is correct |
99 |
Correct |
1661 ms |
4376 KB |
Output is correct |
100 |
Correct |
1714 ms |
4356 KB |
Output is correct |
101 |
Correct |
1581 ms |
4352 KB |
Output is correct |
102 |
Correct |
1477 ms |
4484 KB |
Output is correct |
103 |
Correct |
1431 ms |
4488 KB |
Output is correct |
104 |
Correct |
1363 ms |
4500 KB |
Output is correct |
105 |
Correct |
889 ms |
4448 KB |
Output is correct |