#include<bits/stdc++.h>
using namespace std;
const int N=505;
typedef long double ld;
int n,m;
ld a[N],b[N],dp[N][N],dp2[N][N];
vector<pair<ld,ld>> vec;
ld ans=LDBL_MAX;
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> m;
for(int i=1;i<=n;i++){
cin >> a[i] >> b[i];
if(b[i]<0)b[i]=DBL_MAX;
vec.emplace_back(b[i],a[i]);
}
sort(vec.begin(),vec.end());
for(int i=1;i<=n;i++)tie(b[i],a[i])=vec[i-1];
for(int i=0;i<=n+1;i++)for(int j=0;j<=m+1;j++)dp2[i][j]=DBL_MAX;
dp2[n+1][0]=0;
for(int i=n;i>=1;i--){
for(int j=1;j<=m;j++){
dp2[i][j]=min(dp2[i+1][j],dp2[i+1][j-1]+a[i]);
}
}
for(int i=1;i<=m;i++){
for(int j=0;j<=m;j++)for(int k=0;k<=i;k++)dp[j][k]=LDBL_MAX;
dp[0][1]=0;
for(int j=1;j<=m;j++){
for(int k=1;k<=i;k++){
dp[j][k]=dp[j-1][k]+a[j]/i;
if(k>1&&b[j]<=1000)dp[j][k]=min(dp[j][k],dp[j-1][k-1]+b[j]/(k-1));
}
ans=min(ans,dp[j][i]+dp2[j+1][m-j]/i);
}
}
cout << fixed << setprecision(12) << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
642 ms |
8300 KB |
Output is correct |
2 |
Correct |
641 ms |
8328 KB |
Output is correct |
3 |
Correct |
617 ms |
8296 KB |
Output is correct |
4 |
Correct |
622 ms |
8300 KB |
Output is correct |
5 |
Correct |
662 ms |
8296 KB |
Output is correct |
6 |
Correct |
614 ms |
8420 KB |
Output is correct |
7 |
Correct |
635 ms |
8412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |