#include <bits/stdc++.h>
using namespace std;
const int N = 505;
double 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];
});
if(n!=k){
auto calc=[&](int e){
for(int i=0; i<=n+1; i++){
for(int l=0; l<=n+1; l++){
dp[i][l]=1e9;
}
}
dp[0][0]=0;
for(int i=0; i<n; i++){
for(int l=e; l>=0; l--){
for(int x=n; x>=0; x--){
// cout<<(double)a[i][1]/(double)(l+1)<<"\n";
if(a[i][1]!=-1)
dp[l+1][x] =min<double>(dp[l+1][x], dp[l][x]+(double)a[i][1]/(double)(l+1));
dp[l][x+1]=min<double>(dp[l][x+1], dp[l][x]+((double)a[i][0]/(double)(e+1)));
}
}
}
return dp[e][k-e];
};
double ans=1e9;
for(int i=0; i<=k; i++){
ans=min(ans, calc(i));
}
cout<<setprecision(9)<<ans<<"\n";
}
else{
vector<double> pref(n), suf(n+1);
for(int i=0; i<n; i++){
if(a[i][1]==-1) break;
pref[i]+=(double)(a[i][1])/(double)(i+1);
if(i>0) pref[i]+=pref[i-1];
}
for(int i=n-1; i>=0; i--){
suf[i]=a[i][0];
suf[i]+=suf[i+1];
}
double ans=suf[0];
for(int i=0; i<n; i++){
if(a[i][1]==-1) break;
else{
ans=min<double>(ans, pref[i]+suf[i+1]/(i+2));
}
}
cout<<ans;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
226 ms |
2424 KB |
Output is correct |
6 |
Correct |
1325 ms |
2644 KB |
Output is correct |
7 |
Execution timed out |
2554 ms |
2396 KB |
Time limit exceeded |
8 |
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 |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
226 ms |
2424 KB |
Output is correct |
6 |
Correct |
1325 ms |
2644 KB |
Output is correct |
7 |
Execution timed out |
2554 ms |
2396 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
500 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
500 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
500 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
226 ms |
2424 KB |
Output is correct |
6 |
Correct |
1325 ms |
2644 KB |
Output is correct |
7 |
Execution timed out |
2554 ms |
2396 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |