#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int, int>
#define pii pair<int, pair<int, int> >
#define fi first
#define se second
int n,k;
pair<long double, long double> A[300005];
bool cmp(pair<long double, long double> a, pair<long double, long double> b){
if(a.se == -1)return 0;
if(b.se == -1)return 1;
return a.se < b.se;
}
long double dp[505][505][105];
void solve(){
cin >> n >> k;
int cnt = 0;
for(int i=1;i<=n;i++)cin >> A[i].fi >> A[i].se, cnt += (A[i].se != -1);
sort(A+1, A+n+1, cmp);
for(int i=1;i<=k;i++){
for(int j=0;j<=n;j++){
dp[0][i][j] = 1e18;
if(j)dp[0][0][j] = 1e18;
}
}
dp[0][0][0] = 0.0;
for(int i=1;i<=n;i++){
for(int j=0;j<=k;j++){
for(int x=0;x<=cnt;x++){
dp[i][j][x] = dp[i-1][j][x];
if(j && x && A[i].se > 0)dp[i][j][x] = min(dp[i][j][x], dp[i-1][j-1][x-1] + A[i].se/x);
if(j)dp[i][j][x] = min(dp[i][j][x], dp[i-1][j-1][x] + A[i].fi/(x+1));
}
}
}
long double ans = 1e18;
for(int i=0;i<=cnt;i++)ans= min(ans, dp[n][k][i]);
cout << fixed << setprecision(12) << ans;
}
main(){
ios::sync_with_stdio(0);cin.tie(0);
int t = 1;
//cin >> t;
while(t--){
solve();
}
}
Compilation message
Main.cpp:42:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
42 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
21 ms |
44216 KB |
Output is correct |
6 |
Correct |
40 ms |
105892 KB |
Output is correct |
7 |
Correct |
85 ms |
208656 KB |
Output is correct |
8 |
Correct |
134 ms |
311280 KB |
Output is correct |
9 |
Correct |
175 ms |
414064 KB |
Output is correct |
10 |
Correct |
117 ms |
290764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
21 ms |
44216 KB |
Output is correct |
6 |
Correct |
40 ms |
105892 KB |
Output is correct |
7 |
Correct |
85 ms |
208656 KB |
Output is correct |
8 |
Correct |
134 ms |
311280 KB |
Output is correct |
9 |
Correct |
175 ms |
414064 KB |
Output is correct |
10 |
Correct |
117 ms |
290764 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Incorrect |
612 ms |
130272 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
456 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
456 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
456 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2039 ms |
416352 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
21 ms |
44216 KB |
Output is correct |
6 |
Correct |
40 ms |
105892 KB |
Output is correct |
7 |
Correct |
85 ms |
208656 KB |
Output is correct |
8 |
Correct |
134 ms |
311280 KB |
Output is correct |
9 |
Correct |
175 ms |
414064 KB |
Output is correct |
10 |
Correct |
117 ms |
290764 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Incorrect |
612 ms |
130272 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |