#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, k;
cin >> n >> k;
pair<int, int> a[n];
for(int i = 0; i < n; i++) {
cin >> a[i].second >> a[i].first;
if(a[i].first == -1) a[i].first = 1e9;
}
sort(a, a+n);
double dp[n+1][k+1][k+1];
for(int i = 0; i <= n; i++) {
for(int j = 0; j <= k; j++) {
for(int m = 0; m <= k; m++) {
if(m == 0 && i == 0 && j == 0) dp[i][j][m] = 0;
else if(i == 0 || i < m || i < j || m < j) dp[i][j][m] = 1e9;
else if(j == 0) dp[i][j][m] = min(dp[i-1][j][m-1] + a[i-1].second*1.0/(j+1), dp[i-1][j][m]);
else dp[i][j][m] = min(dp[i-1][j][m-1] + a[i-1].second*1.0/(j+1), min(dp[i-1][j-1][m-1] + a[i-1].first*1.0/j, dp[i-1][j][m]));
}
}
}
double res = 1e9;
for(int i = 0; i <= k; i++) res = min(res, dp[n][i][k]);
cout << fixed << setprecision(5) << res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
9 ms |
10512 KB |
Output is correct |
6 |
Correct |
56 ms |
62556 KB |
Output is correct |
7 |
Correct |
204 ms |
247332 KB |
Output is correct |
8 |
Correct |
403 ms |
554724 KB |
Output is correct |
9 |
Correct |
724 ms |
984648 KB |
Output is correct |
10 |
Correct |
356 ms |
483400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
9 ms |
10512 KB |
Output is correct |
6 |
Correct |
56 ms |
62556 KB |
Output is correct |
7 |
Correct |
204 ms |
247332 KB |
Output is correct |
8 |
Correct |
403 ms |
554724 KB |
Output is correct |
9 |
Correct |
724 ms |
984648 KB |
Output is correct |
10 |
Correct |
356 ms |
483400 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
69 ms |
89712 KB |
Output is correct |
13 |
Correct |
68 ms |
89668 KB |
Output is correct |
14 |
Correct |
71 ms |
89712 KB |
Output is correct |
15 |
Correct |
357 ms |
483376 KB |
Output is correct |
16 |
Correct |
337 ms |
483384 KB |
Output is correct |
17 |
Correct |
347 ms |
483428 KB |
Output is correct |
18 |
Correct |
654 ms |
984620 KB |
Output is correct |
19 |
Correct |
681 ms |
984696 KB |
Output is correct |
20 |
Correct |
639 ms |
984692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
685 ms |
984652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
9 ms |
10512 KB |
Output is correct |
6 |
Correct |
56 ms |
62556 KB |
Output is correct |
7 |
Correct |
204 ms |
247332 KB |
Output is correct |
8 |
Correct |
403 ms |
554724 KB |
Output is correct |
9 |
Correct |
724 ms |
984648 KB |
Output is correct |
10 |
Correct |
356 ms |
483400 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
69 ms |
89712 KB |
Output is correct |
13 |
Correct |
68 ms |
89668 KB |
Output is correct |
14 |
Correct |
71 ms |
89712 KB |
Output is correct |
15 |
Correct |
357 ms |
483376 KB |
Output is correct |
16 |
Correct |
337 ms |
483384 KB |
Output is correct |
17 |
Correct |
347 ms |
483428 KB |
Output is correct |
18 |
Correct |
654 ms |
984620 KB |
Output is correct |
19 |
Correct |
681 ms |
984696 KB |
Output is correct |
20 |
Correct |
639 ms |
984692 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
0 ms |
204 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |