#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<int> A(n), B(n);
for (int i = 0; i < n; i++) {
cin >> A[i] >> B[i];
B[i] = (B[i] == -1 ? 1000000 : B[i]);
}
vector<int> order(n);
iota(order.begin(), order.end(), 0);
sort(order.begin(), order.end(), [&](int i, int j) {
return (B[i] == B[j] ? A[i] > A[j] : B[i] < B[j]);
});
long double ans = 1e9;
for (int m = 0; m <= k; m++) {
vector dp(n + 1, vector<long double>(m + 1, 1e9));
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= i && j <= m; j++) {
if (j + 1 <= m) {
dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + (long double)B[order[i]] / (j + 1));
}
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + (long double)A[order[i]] / (m + 1));
}
}
for (int p = m; p <= n; p++) {
vector<int> C;
for (int i = p; i < n; i++) {
C.push_back(A[order[i]]);
}
sort(C.begin(), C.end());
if ((int)C.size() < k - m) {
break;
}
long double res = dp[p][m];
for (int i = 0; i < k - m; i++) {
res += (long double)C[i] / (m + 1);
}
ans = min(ans, res);
}
}
cout << fixed << setprecision(9) << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
77 ms |
824 KB |
Output is correct |
6 |
Correct |
225 ms |
1528 KB |
Output is correct |
7 |
Correct |
408 ms |
2528 KB |
Output is correct |
8 |
Correct |
597 ms |
3576 KB |
Output is correct |
9 |
Correct |
739 ms |
4588 KB |
Output is correct |
10 |
Correct |
536 ms |
3332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
77 ms |
824 KB |
Output is correct |
6 |
Correct |
225 ms |
1528 KB |
Output is correct |
7 |
Correct |
408 ms |
2528 KB |
Output is correct |
8 |
Correct |
597 ms |
3576 KB |
Output is correct |
9 |
Correct |
739 ms |
4588 KB |
Output is correct |
10 |
Correct |
536 ms |
3332 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
261 ms |
1704 KB |
Output is correct |
13 |
Correct |
377 ms |
1712 KB |
Output is correct |
14 |
Correct |
252 ms |
1756 KB |
Output is correct |
15 |
Correct |
627 ms |
3404 KB |
Output is correct |
16 |
Correct |
715 ms |
3392 KB |
Output is correct |
17 |
Correct |
586 ms |
3272 KB |
Output is correct |
18 |
Correct |
763 ms |
4608 KB |
Output is correct |
19 |
Correct |
753 ms |
4568 KB |
Output is correct |
20 |
Correct |
772 ms |
4624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
794 ms |
4524 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
77 ms |
824 KB |
Output is correct |
6 |
Correct |
225 ms |
1528 KB |
Output is correct |
7 |
Correct |
408 ms |
2528 KB |
Output is correct |
8 |
Correct |
597 ms |
3576 KB |
Output is correct |
9 |
Correct |
739 ms |
4588 KB |
Output is correct |
10 |
Correct |
536 ms |
3332 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
261 ms |
1704 KB |
Output is correct |
13 |
Correct |
377 ms |
1712 KB |
Output is correct |
14 |
Correct |
252 ms |
1756 KB |
Output is correct |
15 |
Correct |
627 ms |
3404 KB |
Output is correct |
16 |
Correct |
715 ms |
3392 KB |
Output is correct |
17 |
Correct |
586 ms |
3272 KB |
Output is correct |
18 |
Correct |
763 ms |
4608 KB |
Output is correct |
19 |
Correct |
753 ms |
4568 KB |
Output is correct |
20 |
Correct |
772 ms |
4624 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |