#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 <= N; i++)
for(int j = 0; j <= K; j++)
for(int k = 0; k <= x; k++)
dp[i][j][k] = 1e9;
dp[0][0][0] = 0;
for(int i = 0; i < N; i++) {
for(int j = 0; j <= K; j++) { // votes
for(int k = 0; k <= x; 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 |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
37 ms |
104776 KB |
Output is correct |
6 |
Correct |
91 ms |
252744 KB |
Output is correct |
7 |
Correct |
180 ms |
499316 KB |
Output is correct |
8 |
Correct |
236 ms |
745984 KB |
Output is correct |
9 |
Correct |
317 ms |
992576 KB |
Output is correct |
10 |
Correct |
214 ms |
696644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
37 ms |
104776 KB |
Output is correct |
6 |
Correct |
91 ms |
252744 KB |
Output is correct |
7 |
Correct |
180 ms |
499316 KB |
Output is correct |
8 |
Correct |
236 ms |
745984 KB |
Output is correct |
9 |
Correct |
317 ms |
992576 KB |
Output is correct |
10 |
Correct |
214 ms |
696644 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
982 ms |
302852 KB |
Output is correct |
13 |
Correct |
754 ms |
302624 KB |
Output is correct |
14 |
Correct |
507 ms |
302344 KB |
Output is correct |
15 |
Execution timed out |
2608 ms |
698020 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
456 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
456 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
724 KB |
Output is correct |
17 |
Correct |
1 ms |
1236 KB |
Output is correct |
18 |
Correct |
1 ms |
1236 KB |
Output is correct |
19 |
Correct |
1 ms |
1484 KB |
Output is correct |
20 |
Correct |
1 ms |
1492 KB |
Output is correct |
21 |
Correct |
1 ms |
1492 KB |
Output is correct |
22 |
Correct |
1 ms |
1620 KB |
Output is correct |
23 |
Correct |
1 ms |
1620 KB |
Output is correct |
24 |
Correct |
1 ms |
1620 KB |
Output is correct |
25 |
Correct |
1 ms |
2132 KB |
Output is correct |
26 |
Correct |
2 ms |
2132 KB |
Output is correct |
27 |
Correct |
1 ms |
1492 KB |
Output is correct |
28 |
Correct |
1 ms |
1620 KB |
Output is correct |
29 |
Correct |
1 ms |
1492 KB |
Output is correct |
30 |
Correct |
1 ms |
1620 KB |
Output is correct |
31 |
Correct |
1 ms |
1492 KB |
Output is correct |
32 |
Correct |
1 ms |
1620 KB |
Output is correct |
33 |
Correct |
1 ms |
1492 KB |
Output is correct |
34 |
Correct |
1 ms |
1492 KB |
Output is correct |
35 |
Correct |
1 ms |
1620 KB |
Output is correct |
36 |
Correct |
1 ms |
1492 KB |
Output is correct |
37 |
Correct |
1 ms |
1620 KB |
Output is correct |
38 |
Correct |
1 ms |
1528 KB |
Output is correct |
39 |
Correct |
1 ms |
1620 KB |
Output is correct |
40 |
Correct |
1 ms |
1492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
456 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
724 KB |
Output is correct |
17 |
Correct |
1 ms |
1236 KB |
Output is correct |
18 |
Correct |
1 ms |
1236 KB |
Output is correct |
19 |
Correct |
1 ms |
1484 KB |
Output is correct |
20 |
Correct |
1 ms |
1492 KB |
Output is correct |
21 |
Correct |
1 ms |
1492 KB |
Output is correct |
22 |
Correct |
1 ms |
1620 KB |
Output is correct |
23 |
Correct |
1 ms |
1620 KB |
Output is correct |
24 |
Correct |
1 ms |
1620 KB |
Output is correct |
25 |
Correct |
1 ms |
2132 KB |
Output is correct |
26 |
Correct |
2 ms |
2132 KB |
Output is correct |
27 |
Correct |
1 ms |
1492 KB |
Output is correct |
28 |
Correct |
1 ms |
1620 KB |
Output is correct |
29 |
Correct |
1 ms |
1492 KB |
Output is correct |
30 |
Correct |
1 ms |
1620 KB |
Output is correct |
31 |
Correct |
1 ms |
1492 KB |
Output is correct |
32 |
Correct |
1 ms |
1620 KB |
Output is correct |
33 |
Correct |
1 ms |
1492 KB |
Output is correct |
34 |
Correct |
1 ms |
1492 KB |
Output is correct |
35 |
Correct |
1 ms |
1620 KB |
Output is correct |
36 |
Correct |
1 ms |
1492 KB |
Output is correct |
37 |
Correct |
1 ms |
1620 KB |
Output is correct |
38 |
Correct |
1 ms |
1528 KB |
Output is correct |
39 |
Correct |
1 ms |
1620 KB |
Output is correct |
40 |
Correct |
1 ms |
1492 KB |
Output is correct |
41 |
Correct |
3 ms |
7380 KB |
Output is correct |
42 |
Correct |
4 ms |
7380 KB |
Output is correct |
43 |
Correct |
7 ms |
13268 KB |
Output is correct |
44 |
Correct |
10 ms |
13268 KB |
Output is correct |
45 |
Correct |
16 ms |
21284 KB |
Output is correct |
46 |
Correct |
14 ms |
21204 KB |
Output is correct |
47 |
Correct |
18 ms |
27192 KB |
Output is correct |
48 |
Correct |
22 ms |
27204 KB |
Output is correct |
49 |
Correct |
38 ms |
33128 KB |
Output is correct |
50 |
Correct |
25 ms |
33108 KB |
Output is correct |
51 |
Correct |
39 ms |
41020 KB |
Output is correct |
52 |
Correct |
55 ms |
41028 KB |
Output is correct |
53 |
Correct |
16 ms |
27084 KB |
Output is correct |
54 |
Correct |
19 ms |
27184 KB |
Output is correct |
55 |
Correct |
29 ms |
27204 KB |
Output is correct |
56 |
Correct |
17 ms |
27092 KB |
Output is correct |
57 |
Correct |
27 ms |
27284 KB |
Output is correct |
58 |
Correct |
25 ms |
27092 KB |
Output is correct |
59 |
Correct |
24 ms |
27092 KB |
Output is correct |
60 |
Correct |
23 ms |
27128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2597 ms |
994168 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
37 ms |
104776 KB |
Output is correct |
6 |
Correct |
91 ms |
252744 KB |
Output is correct |
7 |
Correct |
180 ms |
499316 KB |
Output is correct |
8 |
Correct |
236 ms |
745984 KB |
Output is correct |
9 |
Correct |
317 ms |
992576 KB |
Output is correct |
10 |
Correct |
214 ms |
696644 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
982 ms |
302852 KB |
Output is correct |
13 |
Correct |
754 ms |
302624 KB |
Output is correct |
14 |
Correct |
507 ms |
302344 KB |
Output is correct |
15 |
Execution timed out |
2608 ms |
698020 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |