#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
int32_t 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(m == 0) dp[i][j][m] = 0;
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 |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
216 KB |
Output is correct |
5 |
Correct |
22 ms |
20684 KB |
Output is correct |
6 |
Correct |
110 ms |
124792 KB |
Output is correct |
7 |
Correct |
496 ms |
494392 KB |
Output is correct |
8 |
Runtime error |
448 ms |
1048580 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
216 KB |
Output is correct |
5 |
Correct |
22 ms |
20684 KB |
Output is correct |
6 |
Correct |
110 ms |
124792 KB |
Output is correct |
7 |
Correct |
496 ms |
494392 KB |
Output is correct |
8 |
Runtime error |
448 ms |
1048580 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 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 |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Incorrect |
1 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 |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Incorrect |
1 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 |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
421 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
216 KB |
Output is correct |
5 |
Correct |
22 ms |
20684 KB |
Output is correct |
6 |
Correct |
110 ms |
124792 KB |
Output is correct |
7 |
Correct |
496 ms |
494392 KB |
Output is correct |
8 |
Runtime error |
448 ms |
1048580 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |