#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MX = 505;
int N, K;
int a[MX], b[MX];
vector<pair<int, int>> v;
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin >> N >> K;
int tot = 0;
for(int i = 1; i <= N; i++) {
cin >> a[i] >> b[i];
if(b[i] != -1) tot++;
else b[i] = 1e9;
v.push_back({b[i], a[i]});
}
sort(v.begin(), v.end());
if(K == N) {
vector<vector<double>> dp(N + 5, vector<double>(N + 5, 1e9));
double ans = 1e9;
for(int x = 0; x <= min(K, tot); x++) { // fixed collaborator
for(int i = 0; i < N + 5; i++)
for(int k = 0; k < N + 5; k++)
dp[i][k] = 1e9;
dp[0][0] = 0;
for(int i = 0; i < N; i++) {
for(int k = 0; k <= N; k++) { // num of collaborator
if(dp[i][k] == 1e9) continue;
// ambil vote
dp[i + 1][k] = min(dp[i + 1][k], dp[i][k] + (double) v[i].second / (x + 1));
// ambil collaborator
if(v[i].first != 1e9)
dp[i + 1][k + 1] = min(dp[i + 1][k + 1], dp[i][k] + (double) v[i].first / (k + 1));
}
}
ans = min(ans, dp[N][x]);
}
cout << fixed << setprecision(15) << ans << '\n';
} else {
vector<vector<vector<double>>> dp(N + 5, vector<vector<double>> (N + 5, vector<double>(N + 5, 1e9)));
double ans = 1e9;
for(int x = 0; x <= min(K, tot); x++) { // fixed collaborator
for(int i = 0; i < N + 5; i++)
for(int j = 0; j < N + 5; j++)
for(int k = 0; k < N + 5; k++)
dp[i][j][k] = 1e9;
dp[0][0][0] = 0;
for(int i = 0; i < N; i++) {
for(int j = 0; j <= N; j++) { // votes
for(int k = 0; k <= N; k++) { // num of collaborator
if(dp[i][j][k] == 1e9) continue;
// skip
dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
// ambil vote
dp[i + 1][j + 1][k] = min(dp[i + 1][j + 1][k], dp[i][j][k] + (double) v[i].second / (x + 1));
// ambil collaborator
if(v[i].first != 1e9)
dp[i + 1][j + 1][k + 1] = min(dp[i + 1][j + 1][k + 1], dp[i][j][k] + (double) v[i].first / (k + 1));
}
}
}
ans = min(ans, dp[N][K][x]);
}
cout << fixed << setprecision(15) << ans << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
320 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
583 ms |
1018436 KB |
Output is correct |
6 |
Correct |
534 ms |
1018460 KB |
Output is correct |
7 |
Correct |
554 ms |
1018404 KB |
Output is correct |
8 |
Correct |
561 ms |
1018452 KB |
Output is correct |
9 |
Correct |
1 ms |
2260 KB |
Output is correct |
10 |
Correct |
562 ms |
1018364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
320 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
583 ms |
1018436 KB |
Output is correct |
6 |
Correct |
534 ms |
1018460 KB |
Output is correct |
7 |
Correct |
554 ms |
1018404 KB |
Output is correct |
8 |
Correct |
561 ms |
1018452 KB |
Output is correct |
9 |
Correct |
1 ms |
2260 KB |
Output is correct |
10 |
Correct |
562 ms |
1018364 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Execution timed out |
2580 ms |
1018360 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
500 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
468 KB |
Output is correct |
35 |
Correct |
1 ms |
468 KB |
Output is correct |
36 |
Correct |
1 ms |
352 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
468 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
500 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
468 KB |
Output is correct |
35 |
Correct |
1 ms |
468 KB |
Output is correct |
36 |
Correct |
1 ms |
352 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
468 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
468 KB |
Output is correct |
41 |
Correct |
35 ms |
9776 KB |
Output is correct |
42 |
Correct |
37 ms |
9812 KB |
Output is correct |
43 |
Correct |
66 ms |
9812 KB |
Output is correct |
44 |
Correct |
70 ms |
9808 KB |
Output is correct |
45 |
Correct |
118 ms |
9812 KB |
Output is correct |
46 |
Correct |
154 ms |
9812 KB |
Output is correct |
47 |
Correct |
137 ms |
9812 KB |
Output is correct |
48 |
Correct |
150 ms |
9800 KB |
Output is correct |
49 |
Correct |
175 ms |
9812 KB |
Output is correct |
50 |
Correct |
179 ms |
9812 KB |
Output is correct |
51 |
Correct |
3 ms |
340 KB |
Output is correct |
52 |
Correct |
2 ms |
340 KB |
Output is correct |
53 |
Correct |
134 ms |
9812 KB |
Output is correct |
54 |
Correct |
146 ms |
9812 KB |
Output is correct |
55 |
Correct |
157 ms |
9812 KB |
Output is correct |
56 |
Correct |
133 ms |
9812 KB |
Output is correct |
57 |
Correct |
167 ms |
9804 KB |
Output is correct |
58 |
Correct |
147 ms |
9800 KB |
Output is correct |
59 |
Correct |
137 ms |
9812 KB |
Output is correct |
60 |
Correct |
142 ms |
9812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
285 ms |
2332 KB |
Output is correct |
2 |
Correct |
284 ms |
2328 KB |
Output is correct |
3 |
Correct |
280 ms |
2244 KB |
Output is correct |
4 |
Correct |
282 ms |
2332 KB |
Output is correct |
5 |
Correct |
289 ms |
2328 KB |
Output is correct |
6 |
Correct |
298 ms |
2332 KB |
Output is correct |
7 |
Correct |
297 ms |
2332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
320 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
583 ms |
1018436 KB |
Output is correct |
6 |
Correct |
534 ms |
1018460 KB |
Output is correct |
7 |
Correct |
554 ms |
1018404 KB |
Output is correct |
8 |
Correct |
561 ms |
1018452 KB |
Output is correct |
9 |
Correct |
1 ms |
2260 KB |
Output is correct |
10 |
Correct |
562 ms |
1018364 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Execution timed out |
2580 ms |
1018360 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |