#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MX = 505;
int N, K;
int a[MX], b[MX];
double dp[MX][MX][MX];
vector<pair<int, int>> v;
double f(int x) {
for(int i = 0; i < MX; i++)
for(int j = 0; j < MX; j++)
for(int k = 0; k < MX; 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));
}
}
}
return dp[N][K][x];
}
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());
double ans = 1e9;
int l = 0, r = min(K, tot);
while(r - l > 1) {
int mid = (l + r) >> 1;
if(f(mid) > f(mid + 1))
l = mid;
else
r = mid;
}
cout << fixed << setprecision(15) << min(f(l), f(l + 1)) << '\n';
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:56:14: warning: unused variable 'ans' [-Wunused-variable]
56 | double ans = 1e9;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
517 ms |
1008312 KB |
Output is correct |
2 |
Correct |
408 ms |
1008428 KB |
Output is correct |
3 |
Correct |
438 ms |
1008424 KB |
Output is correct |
4 |
Correct |
414 ms |
1008300 KB |
Output is correct |
5 |
Correct |
621 ms |
1008436 KB |
Output is correct |
6 |
Correct |
672 ms |
1008432 KB |
Output is correct |
7 |
Correct |
638 ms |
1008436 KB |
Output is correct |
8 |
Correct |
624 ms |
1008444 KB |
Output is correct |
9 |
Correct |
621 ms |
1008448 KB |
Output is correct |
10 |
Correct |
662 ms |
1008468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
517 ms |
1008312 KB |
Output is correct |
2 |
Correct |
408 ms |
1008428 KB |
Output is correct |
3 |
Correct |
438 ms |
1008424 KB |
Output is correct |
4 |
Correct |
414 ms |
1008300 KB |
Output is correct |
5 |
Correct |
621 ms |
1008436 KB |
Output is correct |
6 |
Correct |
672 ms |
1008432 KB |
Output is correct |
7 |
Correct |
638 ms |
1008436 KB |
Output is correct |
8 |
Correct |
624 ms |
1008444 KB |
Output is correct |
9 |
Correct |
621 ms |
1008448 KB |
Output is correct |
10 |
Correct |
662 ms |
1008468 KB |
Output is correct |
11 |
Correct |
420 ms |
1008332 KB |
Output is correct |
12 |
Execution timed out |
2610 ms |
1008332 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
424 ms |
1008424 KB |
Output is correct |
2 |
Correct |
597 ms |
1008384 KB |
Output is correct |
3 |
Correct |
598 ms |
1008420 KB |
Output is correct |
4 |
Correct |
776 ms |
1008420 KB |
Output is correct |
5 |
Correct |
794 ms |
1008424 KB |
Output is correct |
6 |
Correct |
773 ms |
1008476 KB |
Output is correct |
7 |
Correct |
920 ms |
1008428 KB |
Output is correct |
8 |
Correct |
747 ms |
1008424 KB |
Output is correct |
9 |
Correct |
747 ms |
1008424 KB |
Output is correct |
10 |
Correct |
749 ms |
1008424 KB |
Output is correct |
11 |
Correct |
767 ms |
1008424 KB |
Output is correct |
12 |
Correct |
753 ms |
1008420 KB |
Output is correct |
13 |
Correct |
782 ms |
1008420 KB |
Output is correct |
14 |
Correct |
761 ms |
1008420 KB |
Output is correct |
15 |
Correct |
975 ms |
1008512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
424 ms |
1008424 KB |
Output is correct |
2 |
Correct |
597 ms |
1008384 KB |
Output is correct |
3 |
Correct |
598 ms |
1008420 KB |
Output is correct |
4 |
Correct |
776 ms |
1008420 KB |
Output is correct |
5 |
Correct |
794 ms |
1008424 KB |
Output is correct |
6 |
Correct |
773 ms |
1008476 KB |
Output is correct |
7 |
Correct |
920 ms |
1008428 KB |
Output is correct |
8 |
Correct |
747 ms |
1008424 KB |
Output is correct |
9 |
Correct |
747 ms |
1008424 KB |
Output is correct |
10 |
Correct |
749 ms |
1008424 KB |
Output is correct |
11 |
Correct |
767 ms |
1008424 KB |
Output is correct |
12 |
Correct |
753 ms |
1008420 KB |
Output is correct |
13 |
Correct |
782 ms |
1008420 KB |
Output is correct |
14 |
Correct |
761 ms |
1008420 KB |
Output is correct |
15 |
Correct |
975 ms |
1008512 KB |
Output is correct |
16 |
Correct |
580 ms |
1008424 KB |
Output is correct |
17 |
Correct |
927 ms |
1008428 KB |
Output is correct |
18 |
Correct |
948 ms |
1008424 KB |
Output is correct |
19 |
Correct |
1098 ms |
1008428 KB |
Output is correct |
20 |
Correct |
1094 ms |
1008420 KB |
Output is correct |
21 |
Correct |
1134 ms |
1008420 KB |
Output is correct |
22 |
Correct |
1168 ms |
1008424 KB |
Output is correct |
23 |
Correct |
1175 ms |
1008428 KB |
Output is correct |
24 |
Correct |
1146 ms |
1008424 KB |
Output is correct |
25 |
Correct |
1377 ms |
1008420 KB |
Output is correct |
26 |
Correct |
1194 ms |
1008424 KB |
Output is correct |
27 |
Correct |
999 ms |
1008424 KB |
Output is correct |
28 |
Correct |
1179 ms |
1008424 KB |
Output is correct |
29 |
Correct |
1183 ms |
1008432 KB |
Output is correct |
30 |
Correct |
1194 ms |
1008428 KB |
Output is correct |
31 |
Correct |
1167 ms |
1008436 KB |
Output is correct |
32 |
Correct |
1172 ms |
1008472 KB |
Output is correct |
33 |
Correct |
1187 ms |
1008428 KB |
Output is correct |
34 |
Correct |
984 ms |
1008432 KB |
Output is correct |
35 |
Correct |
1121 ms |
1008428 KB |
Output is correct |
36 |
Correct |
1169 ms |
1008428 KB |
Output is correct |
37 |
Correct |
1136 ms |
1008432 KB |
Output is correct |
38 |
Correct |
1160 ms |
1008436 KB |
Output is correct |
39 |
Correct |
1128 ms |
1008412 KB |
Output is correct |
40 |
Correct |
1136 ms |
1008424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
424 ms |
1008424 KB |
Output is correct |
2 |
Correct |
597 ms |
1008384 KB |
Output is correct |
3 |
Correct |
598 ms |
1008420 KB |
Output is correct |
4 |
Correct |
776 ms |
1008420 KB |
Output is correct |
5 |
Correct |
794 ms |
1008424 KB |
Output is correct |
6 |
Correct |
773 ms |
1008476 KB |
Output is correct |
7 |
Correct |
920 ms |
1008428 KB |
Output is correct |
8 |
Correct |
747 ms |
1008424 KB |
Output is correct |
9 |
Correct |
747 ms |
1008424 KB |
Output is correct |
10 |
Correct |
749 ms |
1008424 KB |
Output is correct |
11 |
Correct |
767 ms |
1008424 KB |
Output is correct |
12 |
Correct |
753 ms |
1008420 KB |
Output is correct |
13 |
Correct |
782 ms |
1008420 KB |
Output is correct |
14 |
Correct |
761 ms |
1008420 KB |
Output is correct |
15 |
Correct |
975 ms |
1008512 KB |
Output is correct |
16 |
Correct |
580 ms |
1008424 KB |
Output is correct |
17 |
Correct |
927 ms |
1008428 KB |
Output is correct |
18 |
Correct |
948 ms |
1008424 KB |
Output is correct |
19 |
Correct |
1098 ms |
1008428 KB |
Output is correct |
20 |
Correct |
1094 ms |
1008420 KB |
Output is correct |
21 |
Correct |
1134 ms |
1008420 KB |
Output is correct |
22 |
Correct |
1168 ms |
1008424 KB |
Output is correct |
23 |
Correct |
1175 ms |
1008428 KB |
Output is correct |
24 |
Correct |
1146 ms |
1008424 KB |
Output is correct |
25 |
Correct |
1377 ms |
1008420 KB |
Output is correct |
26 |
Correct |
1194 ms |
1008424 KB |
Output is correct |
27 |
Correct |
999 ms |
1008424 KB |
Output is correct |
28 |
Correct |
1179 ms |
1008424 KB |
Output is correct |
29 |
Correct |
1183 ms |
1008432 KB |
Output is correct |
30 |
Correct |
1194 ms |
1008428 KB |
Output is correct |
31 |
Correct |
1167 ms |
1008436 KB |
Output is correct |
32 |
Correct |
1172 ms |
1008472 KB |
Output is correct |
33 |
Correct |
1187 ms |
1008428 KB |
Output is correct |
34 |
Correct |
984 ms |
1008432 KB |
Output is correct |
35 |
Correct |
1121 ms |
1008428 KB |
Output is correct |
36 |
Correct |
1169 ms |
1008428 KB |
Output is correct |
37 |
Correct |
1136 ms |
1008432 KB |
Output is correct |
38 |
Correct |
1160 ms |
1008436 KB |
Output is correct |
39 |
Correct |
1128 ms |
1008412 KB |
Output is correct |
40 |
Correct |
1136 ms |
1008424 KB |
Output is correct |
41 |
Correct |
1155 ms |
1008432 KB |
Output is correct |
42 |
Correct |
1189 ms |
1008432 KB |
Output is correct |
43 |
Correct |
1381 ms |
1008424 KB |
Output is correct |
44 |
Correct |
1350 ms |
1008440 KB |
Output is correct |
45 |
Correct |
1412 ms |
1008492 KB |
Output is correct |
46 |
Correct |
1540 ms |
1008460 KB |
Output is correct |
47 |
Correct |
1512 ms |
1008548 KB |
Output is correct |
48 |
Correct |
1565 ms |
1008492 KB |
Output is correct |
49 |
Correct |
1560 ms |
1008432 KB |
Output is correct |
50 |
Correct |
1515 ms |
1008428 KB |
Output is correct |
51 |
Correct |
1712 ms |
1008432 KB |
Output is correct |
52 |
Correct |
1745 ms |
1008432 KB |
Output is correct |
53 |
Correct |
1529 ms |
1008460 KB |
Output is correct |
54 |
Correct |
1570 ms |
1008520 KB |
Output is correct |
55 |
Correct |
1529 ms |
1008472 KB |
Output is correct |
56 |
Correct |
1538 ms |
1008432 KB |
Output is correct |
57 |
Correct |
1530 ms |
1008436 KB |
Output is correct |
58 |
Correct |
1554 ms |
1008332 KB |
Output is correct |
59 |
Correct |
1512 ms |
1008432 KB |
Output is correct |
60 |
Correct |
1541 ms |
1008428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2603 ms |
1008316 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
517 ms |
1008312 KB |
Output is correct |
2 |
Correct |
408 ms |
1008428 KB |
Output is correct |
3 |
Correct |
438 ms |
1008424 KB |
Output is correct |
4 |
Correct |
414 ms |
1008300 KB |
Output is correct |
5 |
Correct |
621 ms |
1008436 KB |
Output is correct |
6 |
Correct |
672 ms |
1008432 KB |
Output is correct |
7 |
Correct |
638 ms |
1008436 KB |
Output is correct |
8 |
Correct |
624 ms |
1008444 KB |
Output is correct |
9 |
Correct |
621 ms |
1008448 KB |
Output is correct |
10 |
Correct |
662 ms |
1008468 KB |
Output is correct |
11 |
Correct |
420 ms |
1008332 KB |
Output is correct |
12 |
Execution timed out |
2610 ms |
1008332 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |