#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=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=1;i<=n;i++)tie(b[i],a[i])=vec[i-1];
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=2;i<=m;i++)dp[0][i]=LDBL_MAX;
for(int i=1;i<=m;i++){
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
533 ms |
8296 KB |
Output is correct |
2 |
Correct |
553 ms |
8372 KB |
Output is correct |
3 |
Correct |
517 ms |
8324 KB |
Output is correct |
4 |
Correct |
513 ms |
8240 KB |
Output is correct |
5 |
Correct |
549 ms |
8296 KB |
Output is correct |
6 |
Correct |
512 ms |
8300 KB |
Output is correct |
7 |
Correct |
510 ms |
8292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
- |