#include <bits/stdc++.h>
using namespace std;
const int N = 505;
double dp[N][N], mi[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];
});
double ans=1e9;
for(int i=0; i<=n; i++){
for(int l=0; l<=n; l++){
mi[i][l]=1e9;
}
}
mi[n][0]=0;
for(int i=n-1; i>=0; i--){
mi[i][0]=0;
for(int l=n; l>0; l--){
mi[i][l]=min(mi[i][l], mi[i+1][l-1]+a[i][0]);
/// cout<<mi[i+1][l-1]<<" "<<mi[i][l]<<"\n";
}
}
auto calc=[&](int e){
for(int i=0; i<=n+1; i++){
for(int l=0; l<=n+1; l++){
dp[i][l]=1e9;
}
}
for(int i=0; i<=k; i++){
if(a[i][1]==-1) break;
dp[i][0]=(i==0?0:dp[i-1][0])+(double)a[i][0]/(double)(e+1);
if(i>0)
for(int l=e; l>=1; l--)
dp[i][l] =min<double>(dp[i-1][l-1]+(double)a[i][1]/(double)(l), dp[i-1][l]+((double)a[i][0])/(double)(e+1));
else dp[i][1]=a[i][1];
}
for(int i=0; i<k; i++){
if(mi[i+1][k-i-1]!=1e9&&dp[i][e]!=(1e9))
ans=min(ans, dp[i][e]+(double)mi[i+1][k-i-1]/(double)(e+1));
}
};
for(int i=1; i<=k; i++){
calc(i);
}
ans=min(ans, mi[0][k]);
cout<<fixed<<" "<<setprecision(9)<<ans<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
6 ms |
4444 KB |
Output is correct |
6 |
Correct |
13 ms |
4444 KB |
Output is correct |
7 |
Correct |
30 ms |
4188 KB |
Output is correct |
8 |
Correct |
37 ms |
4440 KB |
Output is correct |
9 |
Correct |
43 ms |
4188 KB |
Output is correct |
10 |
Correct |
31 ms |
4440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
6 ms |
4444 KB |
Output is correct |
6 |
Correct |
13 ms |
4444 KB |
Output is correct |
7 |
Correct |
30 ms |
4188 KB |
Output is correct |
8 |
Correct |
37 ms |
4440 KB |
Output is correct |
9 |
Correct |
43 ms |
4188 KB |
Output is correct |
10 |
Correct |
31 ms |
4440 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
17 ms |
4440 KB |
Output is correct |
13 |
Incorrect |
17 ms |
4444 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
144 ms |
4340 KB |
Output is correct |
2 |
Correct |
141 ms |
4416 KB |
Output is correct |
3 |
Correct |
140 ms |
4416 KB |
Output is correct |
4 |
Correct |
142 ms |
4416 KB |
Output is correct |
5 |
Correct |
146 ms |
4420 KB |
Output is correct |
6 |
Correct |
151 ms |
4416 KB |
Output is correct |
7 |
Correct |
140 ms |
4416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
6 ms |
4444 KB |
Output is correct |
6 |
Correct |
13 ms |
4444 KB |
Output is correct |
7 |
Correct |
30 ms |
4188 KB |
Output is correct |
8 |
Correct |
37 ms |
4440 KB |
Output is correct |
9 |
Correct |
43 ms |
4188 KB |
Output is correct |
10 |
Correct |
31 ms |
4440 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
17 ms |
4440 KB |
Output is correct |
13 |
Incorrect |
17 ms |
4444 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |