#include <bits/stdc++.h>
using namespace std;
const int N = 505;
array<double, 2> dp[N][N];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, k; cin >> n >> k;
vector<array<int, 2>> a(n);
for(auto &[i, l]: a) cin >> i >> l;
sort(a.begin(), a.end(), [&](auto x, auto y){
if(x[1]==y[1]) return x[0] < y[0];
else if(y[1]==-1) return true;
else if(x[1]==-1) return false;
return x[1]<y[1];
});
for(int i=0; i<=n; i++){
for(int l=0; l<=n; l++){
dp[i][l]={1e9, 1e9};
}
}
dp[0][0]={0, 0};
for(int i=0; i<n; i++){
for(int l=n; l>=0; l--){
for(int x=n-1; x>=0; x--){
// cout<<(double)a[i][1]/(double)(l+1)<<"\n";
if(a[i][1]!=-1)
dp[l+1][x]=min(dp[l+1][x], {dp[l][x][0]+(double)a[i][1]/(double)(l+1), dp[l][x][1]});
dp[l][x+1]=min(dp[l][x+1], {dp[l][x][0], dp[l][x][1]+a[i][0]});
}
}
}
double ans=1e9;
for(int i=0; i<=k; i++){
ans=min(ans, dp[i][k-i][0]+dp[i][k-i][1]/(double)(i+1));
}
cout<<fixed<<setprecision(9)<<ans<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
352 KB |
Output is correct |
5 |
Correct |
453 ms |
4400 KB |
Output is correct |
6 |
Correct |
453 ms |
4416 KB |
Output is correct |
7 |
Correct |
442 ms |
4404 KB |
Output is correct |
8 |
Correct |
478 ms |
4436 KB |
Output is correct |
9 |
Correct |
453 ms |
4440 KB |
Output is correct |
10 |
Correct |
449 ms |
4184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
352 KB |
Output is correct |
5 |
Correct |
453 ms |
4400 KB |
Output is correct |
6 |
Correct |
453 ms |
4416 KB |
Output is correct |
7 |
Correct |
442 ms |
4404 KB |
Output is correct |
8 |
Correct |
478 ms |
4436 KB |
Output is correct |
9 |
Correct |
453 ms |
4440 KB |
Output is correct |
10 |
Correct |
449 ms |
4184 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
627 ms |
4420 KB |
Output is correct |
13 |
Correct |
587 ms |
4436 KB |
Output is correct |
14 |
Correct |
496 ms |
4188 KB |
Output is correct |
15 |
Correct |
616 ms |
4408 KB |
Output is correct |
16 |
Correct |
570 ms |
4436 KB |
Output is correct |
17 |
Correct |
479 ms |
4400 KB |
Output is correct |
18 |
Correct |
614 ms |
4188 KB |
Output is correct |
19 |
Correct |
577 ms |
4436 KB |
Output is correct |
20 |
Correct |
488 ms |
4436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
637 ms |
4404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
352 KB |
Output is correct |
5 |
Correct |
453 ms |
4400 KB |
Output is correct |
6 |
Correct |
453 ms |
4416 KB |
Output is correct |
7 |
Correct |
442 ms |
4404 KB |
Output is correct |
8 |
Correct |
478 ms |
4436 KB |
Output is correct |
9 |
Correct |
453 ms |
4440 KB |
Output is correct |
10 |
Correct |
449 ms |
4184 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
627 ms |
4420 KB |
Output is correct |
13 |
Correct |
587 ms |
4436 KB |
Output is correct |
14 |
Correct |
496 ms |
4188 KB |
Output is correct |
15 |
Correct |
616 ms |
4408 KB |
Output is correct |
16 |
Correct |
570 ms |
4436 KB |
Output is correct |
17 |
Correct |
479 ms |
4400 KB |
Output is correct |
18 |
Correct |
614 ms |
4188 KB |
Output is correct |
19 |
Correct |
577 ms |
4436 KB |
Output is correct |
20 |
Correct |
488 ms |
4436 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |