#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);
long double ans = 1e18;
for(int y=0;y<=cnt;y++){
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<=y;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/(y+1));
}
}
}
ans = min(ans, dp[n][k][y]);
}
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:47:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
47 | main(){
| ^~~~
# |
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 |
0 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
16 ms |
44196 KB |
Output is correct |
6 |
Correct |
38 ms |
105892 KB |
Output is correct |
7 |
Correct |
77 ms |
208620 KB |
Output is correct |
8 |
Correct |
132 ms |
311352 KB |
Output is correct |
9 |
Correct |
164 ms |
414072 KB |
Output is correct |
10 |
Correct |
110 ms |
290756 KB |
Output is correct |
# |
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 |
0 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
16 ms |
44196 KB |
Output is correct |
6 |
Correct |
38 ms |
105892 KB |
Output is correct |
7 |
Correct |
77 ms |
208620 KB |
Output is correct |
8 |
Correct |
132 ms |
311352 KB |
Output is correct |
9 |
Correct |
164 ms |
414072 KB |
Output is correct |
10 |
Correct |
110 ms |
290756 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Execution timed out |
2588 ms |
126948 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
452 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
452 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
2 ms |
724 KB |
Output is correct |
18 |
Correct |
1 ms |
724 KB |
Output is correct |
19 |
Correct |
2 ms |
852 KB |
Output is correct |
20 |
Correct |
1 ms |
836 KB |
Output is correct |
21 |
Correct |
1 ms |
852 KB |
Output is correct |
22 |
Correct |
2 ms |
852 KB |
Output is correct |
23 |
Correct |
1 ms |
852 KB |
Output is correct |
24 |
Correct |
1 ms |
852 KB |
Output is correct |
25 |
Correct |
2 ms |
1092 KB |
Output is correct |
26 |
Correct |
3 ms |
1108 KB |
Output is correct |
27 |
Correct |
2 ms |
852 KB |
Output is correct |
28 |
Correct |
3 ms |
852 KB |
Output is correct |
29 |
Correct |
3 ms |
852 KB |
Output is correct |
30 |
Correct |
2 ms |
852 KB |
Output is correct |
31 |
Correct |
2 ms |
852 KB |
Output is correct |
32 |
Correct |
2 ms |
852 KB |
Output is correct |
33 |
Correct |
1 ms |
856 KB |
Output is correct |
34 |
Correct |
1 ms |
852 KB |
Output is correct |
35 |
Correct |
2 ms |
852 KB |
Output is correct |
36 |
Correct |
2 ms |
852 KB |
Output is correct |
37 |
Correct |
2 ms |
852 KB |
Output is correct |
38 |
Correct |
2 ms |
852 KB |
Output is correct |
39 |
Correct |
2 ms |
852 KB |
Output is correct |
40 |
Correct |
1 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
452 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
2 ms |
724 KB |
Output is correct |
18 |
Correct |
1 ms |
724 KB |
Output is correct |
19 |
Correct |
2 ms |
852 KB |
Output is correct |
20 |
Correct |
1 ms |
836 KB |
Output is correct |
21 |
Correct |
1 ms |
852 KB |
Output is correct |
22 |
Correct |
2 ms |
852 KB |
Output is correct |
23 |
Correct |
1 ms |
852 KB |
Output is correct |
24 |
Correct |
1 ms |
852 KB |
Output is correct |
25 |
Correct |
2 ms |
1092 KB |
Output is correct |
26 |
Correct |
3 ms |
1108 KB |
Output is correct |
27 |
Correct |
2 ms |
852 KB |
Output is correct |
28 |
Correct |
3 ms |
852 KB |
Output is correct |
29 |
Correct |
3 ms |
852 KB |
Output is correct |
30 |
Correct |
2 ms |
852 KB |
Output is correct |
31 |
Correct |
2 ms |
852 KB |
Output is correct |
32 |
Correct |
2 ms |
852 KB |
Output is correct |
33 |
Correct |
1 ms |
856 KB |
Output is correct |
34 |
Correct |
1 ms |
852 KB |
Output is correct |
35 |
Correct |
2 ms |
852 KB |
Output is correct |
36 |
Correct |
2 ms |
852 KB |
Output is correct |
37 |
Correct |
2 ms |
852 KB |
Output is correct |
38 |
Correct |
2 ms |
852 KB |
Output is correct |
39 |
Correct |
2 ms |
852 KB |
Output is correct |
40 |
Correct |
1 ms |
852 KB |
Output is correct |
41 |
Correct |
116 ms |
3508 KB |
Output is correct |
42 |
Correct |
90 ms |
3488 KB |
Output is correct |
43 |
Correct |
221 ms |
6008 KB |
Output is correct |
44 |
Correct |
150 ms |
6092 KB |
Output is correct |
45 |
Correct |
413 ms |
9384 KB |
Output is correct |
46 |
Correct |
258 ms |
9292 KB |
Output is correct |
47 |
Correct |
502 ms |
11704 KB |
Output is correct |
48 |
Correct |
315 ms |
11976 KB |
Output is correct |
49 |
Correct |
624 ms |
14348 KB |
Output is correct |
50 |
Correct |
441 ms |
14240 KB |
Output is correct |
51 |
Correct |
816 ms |
17600 KB |
Output is correct |
52 |
Correct |
569 ms |
17664 KB |
Output is correct |
53 |
Correct |
547 ms |
11992 KB |
Output is correct |
54 |
Correct |
507 ms |
11892 KB |
Output is correct |
55 |
Correct |
500 ms |
11856 KB |
Output is correct |
56 |
Correct |
496 ms |
11992 KB |
Output is correct |
57 |
Correct |
510 ms |
11852 KB |
Output is correct |
58 |
Correct |
502 ms |
11760 KB |
Output is correct |
59 |
Correct |
510 ms |
11836 KB |
Output is correct |
60 |
Correct |
504 ms |
11836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2615 ms |
414304 KB |
Time limit exceeded |
2 |
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 |
0 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
16 ms |
44196 KB |
Output is correct |
6 |
Correct |
38 ms |
105892 KB |
Output is correct |
7 |
Correct |
77 ms |
208620 KB |
Output is correct |
8 |
Correct |
132 ms |
311352 KB |
Output is correct |
9 |
Correct |
164 ms |
414072 KB |
Output is correct |
10 |
Correct |
110 ms |
290756 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Execution timed out |
2588 ms |
126948 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |