#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,k;cin>>n>>k;
vector<pair<double long,double long>>arr,temp;
for (int i = 0;i<n;++i){
double long x,y;cin>>x>>y;
if (y == -1){
temp.push_back({x,y});
}
else{
arr.push_back({x,y});
}
}
sort(arr.begin(),arr.end(),[&](auto x,auto y){
if (x.second == y.second)return x.first < y.first;
return x.second < y.second;
});
sort(temp.begin(),temp.end(),[&](auto x,auto y){
return x.first < y.first;
});
for (auto x:temp)arr.push_back(x);
double long mxn = 1e8;
vector<vector<double long>>dp(n + 1,vector<double long>(n + 1,mxn));
dp[0][0] = 0.0;
for (int i = 0;i<n;++i){
vector<vector<double long>>cur_dp(n + 1,vector<double long>(n + 1,mxn));
for (int j = 0;j<=i;++j){
for (int p = 0;p <= j;++p){
cur_dp[j][p] = min(cur_dp[j][p],dp[j][p]);
cur_dp[j + 1][p + 1] = min(cur_dp[j + 1][p + 1],dp[j + 1][p + 1]);
cur_dp[j + 1][p] = min(cur_dp[j + 1][p],dp[j + 1][p]);
if (arr[i].second!=-1){
cur_dp[j + 1][p + 1] = min(dp[j][p] + (double long)(arr[i].second / (p + 1)),cur_dp[j + 1][p + 1]);
}
cur_dp[j + 1][p] = min(cur_dp[j + 1][p],dp[j][p] + (double long)(arr[i].first / (p + 1)));
}
}
swap(cur_dp,dp);
}
double long ans = mxn;
for (int i = 0;i<=n;++i){
ans = min(ans,dp[k][i]);
}
cout<<fixed<<setprecision(15)<<ans<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
909 ms |
8524 KB |
Output is correct |
6 |
Correct |
912 ms |
8520 KB |
Output is correct |
7 |
Correct |
884 ms |
8488 KB |
Output is correct |
8 |
Correct |
923 ms |
8628 KB |
Output is correct |
9 |
Correct |
960 ms |
8304 KB |
Output is correct |
10 |
Correct |
941 ms |
8728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
909 ms |
8524 KB |
Output is correct |
6 |
Correct |
912 ms |
8520 KB |
Output is correct |
7 |
Correct |
884 ms |
8488 KB |
Output is correct |
8 |
Correct |
923 ms |
8628 KB |
Output is correct |
9 |
Correct |
960 ms |
8304 KB |
Output is correct |
10 |
Correct |
941 ms |
8728 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1025 ms |
8468 KB |
Output is correct |
13 |
Correct |
950 ms |
8516 KB |
Output is correct |
14 |
Correct |
963 ms |
8444 KB |
Output is correct |
15 |
Correct |
1006 ms |
8488 KB |
Output is correct |
16 |
Correct |
939 ms |
8484 KB |
Output is correct |
17 |
Correct |
902 ms |
8408 KB |
Output is correct |
18 |
Correct |
1006 ms |
8408 KB |
Output is correct |
19 |
Correct |
954 ms |
8428 KB |
Output is correct |
20 |
Correct |
968 ms |
8432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1035 ms |
8600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
909 ms |
8524 KB |
Output is correct |
6 |
Correct |
912 ms |
8520 KB |
Output is correct |
7 |
Correct |
884 ms |
8488 KB |
Output is correct |
8 |
Correct |
923 ms |
8628 KB |
Output is correct |
9 |
Correct |
960 ms |
8304 KB |
Output is correct |
10 |
Correct |
941 ms |
8728 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1025 ms |
8468 KB |
Output is correct |
13 |
Correct |
950 ms |
8516 KB |
Output is correct |
14 |
Correct |
963 ms |
8444 KB |
Output is correct |
15 |
Correct |
1006 ms |
8488 KB |
Output is correct |
16 |
Correct |
939 ms |
8484 KB |
Output is correct |
17 |
Correct |
902 ms |
8408 KB |
Output is correct |
18 |
Correct |
1006 ms |
8408 KB |
Output is correct |
19 |
Correct |
954 ms |
8428 KB |
Output is correct |
20 |
Correct |
968 ms |
8432 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
300 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |