#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=1;i<=n;i++)tie(b[i],a[i])=vec[i-1];
for(int i=1;i<=m;i++)dp2[n+1][i]=DBL_MAX;
dp2[n+1][0]=0;
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]);
}
ans=min(ans,dp2[i][m]);
}
for(int i=1;i<=m;i++){
for(int j=0;j<=m;j++)for(int k=0;k<=i;k++)dp[j][k]=LDBL_MAX;
dp[0][1]=0;
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
3028 KB |
Output is correct |
6 |
Correct |
9 ms |
4088 KB |
Output is correct |
7 |
Correct |
51 ms |
6216 KB |
Output is correct |
8 |
Correct |
169 ms |
7276 KB |
Output is correct |
9 |
Correct |
383 ms |
8292 KB |
Output is correct |
10 |
Correct |
133 ms |
6996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
3028 KB |
Output is correct |
6 |
Correct |
9 ms |
4088 KB |
Output is correct |
7 |
Correct |
51 ms |
6216 KB |
Output is correct |
8 |
Correct |
169 ms |
7276 KB |
Output is correct |
9 |
Correct |
383 ms |
8292 KB |
Output is correct |
10 |
Correct |
133 ms |
6996 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
19 ms |
4520 KB |
Output is correct |
13 |
Correct |
19 ms |
4408 KB |
Output is correct |
14 |
Correct |
17 ms |
4504 KB |
Output is correct |
15 |
Correct |
214 ms |
7104 KB |
Output is correct |
16 |
Correct |
201 ms |
7276 KB |
Output is correct |
17 |
Correct |
155 ms |
7112 KB |
Output is correct |
18 |
Correct |
625 ms |
8296 KB |
Output is correct |
19 |
Correct |
552 ms |
8288 KB |
Output is correct |
20 |
Correct |
481 ms |
8340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 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 |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 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 |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
0 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
0 ms |
468 KB |
Output is correct |
23 |
Correct |
0 ms |
468 KB |
Output is correct |
24 |
Correct |
0 ms |
468 KB |
Output is correct |
25 |
Correct |
0 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
0 ms |
468 KB |
Output is correct |
28 |
Correct |
0 ms |
468 KB |
Output is correct |
29 |
Correct |
0 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
0 ms |
468 KB |
Output is correct |
33 |
Correct |
0 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
468 KB |
Output is correct |
35 |
Correct |
1 ms |
468 KB |
Output is correct |
36 |
Correct |
1 ms |
468 KB |
Output is correct |
37 |
Correct |
0 ms |
468 KB |
Output is correct |
38 |
Correct |
0 ms |
468 KB |
Output is correct |
39 |
Correct |
0 ms |
468 KB |
Output is correct |
40 |
Correct |
0 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 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 |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
0 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
0 ms |
468 KB |
Output is correct |
23 |
Correct |
0 ms |
468 KB |
Output is correct |
24 |
Correct |
0 ms |
468 KB |
Output is correct |
25 |
Correct |
0 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
0 ms |
468 KB |
Output is correct |
28 |
Correct |
0 ms |
468 KB |
Output is correct |
29 |
Correct |
0 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
0 ms |
468 KB |
Output is correct |
33 |
Correct |
0 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
468 KB |
Output is correct |
35 |
Correct |
1 ms |
468 KB |
Output is correct |
36 |
Correct |
1 ms |
468 KB |
Output is correct |
37 |
Correct |
0 ms |
468 KB |
Output is correct |
38 |
Correct |
0 ms |
468 KB |
Output is correct |
39 |
Correct |
0 ms |
468 KB |
Output is correct |
40 |
Correct |
0 ms |
468 KB |
Output is correct |
41 |
Correct |
1 ms |
852 KB |
Output is correct |
42 |
Correct |
1 ms |
852 KB |
Output is correct |
43 |
Correct |
1 ms |
852 KB |
Output is correct |
44 |
Correct |
1 ms |
852 KB |
Output is correct |
45 |
Correct |
1 ms |
980 KB |
Output is correct |
46 |
Correct |
1 ms |
980 KB |
Output is correct |
47 |
Correct |
2 ms |
1104 KB |
Output is correct |
48 |
Correct |
2 ms |
1104 KB |
Output is correct |
49 |
Correct |
3 ms |
1224 KB |
Output is correct |
50 |
Correct |
4 ms |
1228 KB |
Output is correct |
51 |
Correct |
6 ms |
1472 KB |
Output is correct |
52 |
Correct |
6 ms |
1492 KB |
Output is correct |
53 |
Correct |
2 ms |
1108 KB |
Output is correct |
54 |
Correct |
2 ms |
1100 KB |
Output is correct |
55 |
Correct |
2 ms |
1100 KB |
Output is correct |
56 |
Correct |
2 ms |
1108 KB |
Output is correct |
57 |
Correct |
2 ms |
1108 KB |
Output is correct |
58 |
Correct |
3 ms |
1100 KB |
Output is correct |
59 |
Correct |
2 ms |
1104 KB |
Output is correct |
60 |
Correct |
2 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
625 ms |
8300 KB |
Output is correct |
2 |
Correct |
620 ms |
8292 KB |
Output is correct |
3 |
Correct |
651 ms |
8412 KB |
Output is correct |
4 |
Correct |
623 ms |
8332 KB |
Output is correct |
5 |
Correct |
614 ms |
8288 KB |
Output is correct |
6 |
Correct |
619 ms |
8292 KB |
Output is correct |
7 |
Correct |
613 ms |
8192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
3028 KB |
Output is correct |
6 |
Correct |
9 ms |
4088 KB |
Output is correct |
7 |
Correct |
51 ms |
6216 KB |
Output is correct |
8 |
Correct |
169 ms |
7276 KB |
Output is correct |
9 |
Correct |
383 ms |
8292 KB |
Output is correct |
10 |
Correct |
133 ms |
6996 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
19 ms |
4520 KB |
Output is correct |
13 |
Correct |
19 ms |
4408 KB |
Output is correct |
14 |
Correct |
17 ms |
4504 KB |
Output is correct |
15 |
Correct |
214 ms |
7104 KB |
Output is correct |
16 |
Correct |
201 ms |
7276 KB |
Output is correct |
17 |
Correct |
155 ms |
7112 KB |
Output is correct |
18 |
Correct |
625 ms |
8296 KB |
Output is correct |
19 |
Correct |
552 ms |
8288 KB |
Output is correct |
20 |
Correct |
481 ms |
8340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
0 ms |
340 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
0 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |
34 |
Correct |
0 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
0 ms |
340 KB |
Output is correct |
37 |
Correct |
0 ms |
468 KB |
Output is correct |
38 |
Correct |
1 ms |
468 KB |
Output is correct |
39 |
Correct |
1 ms |
468 KB |
Output is correct |
40 |
Correct |
0 ms |
468 KB |
Output is correct |
41 |
Correct |
1 ms |
468 KB |
Output is correct |
42 |
Correct |
0 ms |
468 KB |
Output is correct |
43 |
Correct |
0 ms |
468 KB |
Output is correct |
44 |
Correct |
0 ms |
468 KB |
Output is correct |
45 |
Correct |
0 ms |
468 KB |
Output is correct |
46 |
Correct |
1 ms |
468 KB |
Output is correct |
47 |
Correct |
0 ms |
468 KB |
Output is correct |
48 |
Correct |
0 ms |
468 KB |
Output is correct |
49 |
Correct |
0 ms |
468 KB |
Output is correct |
50 |
Correct |
1 ms |
468 KB |
Output is correct |
51 |
Correct |
1 ms |
468 KB |
Output is correct |
52 |
Correct |
0 ms |
468 KB |
Output is correct |
53 |
Correct |
0 ms |
468 KB |
Output is correct |
54 |
Correct |
1 ms |
468 KB |
Output is correct |
55 |
Correct |
1 ms |
468 KB |
Output is correct |
56 |
Correct |
1 ms |
468 KB |
Output is correct |
57 |
Correct |
0 ms |
468 KB |
Output is correct |
58 |
Correct |
0 ms |
468 KB |
Output is correct |
59 |
Correct |
0 ms |
468 KB |
Output is correct |
60 |
Correct |
0 ms |
468 KB |
Output is correct |
61 |
Correct |
1 ms |
852 KB |
Output is correct |
62 |
Correct |
1 ms |
852 KB |
Output is correct |
63 |
Correct |
1 ms |
852 KB |
Output is correct |
64 |
Correct |
1 ms |
852 KB |
Output is correct |
65 |
Correct |
1 ms |
980 KB |
Output is correct |
66 |
Correct |
1 ms |
980 KB |
Output is correct |
67 |
Correct |
2 ms |
1104 KB |
Output is correct |
68 |
Correct |
2 ms |
1104 KB |
Output is correct |
69 |
Correct |
3 ms |
1224 KB |
Output is correct |
70 |
Correct |
4 ms |
1228 KB |
Output is correct |
71 |
Correct |
6 ms |
1472 KB |
Output is correct |
72 |
Correct |
6 ms |
1492 KB |
Output is correct |
73 |
Correct |
2 ms |
1108 KB |
Output is correct |
74 |
Correct |
2 ms |
1100 KB |
Output is correct |
75 |
Correct |
2 ms |
1100 KB |
Output is correct |
76 |
Correct |
2 ms |
1108 KB |
Output is correct |
77 |
Correct |
2 ms |
1108 KB |
Output is correct |
78 |
Correct |
3 ms |
1100 KB |
Output is correct |
79 |
Correct |
2 ms |
1104 KB |
Output is correct |
80 |
Correct |
2 ms |
1108 KB |
Output is correct |
81 |
Correct |
625 ms |
8300 KB |
Output is correct |
82 |
Correct |
620 ms |
8292 KB |
Output is correct |
83 |
Correct |
651 ms |
8412 KB |
Output is correct |
84 |
Correct |
623 ms |
8332 KB |
Output is correct |
85 |
Correct |
614 ms |
8288 KB |
Output is correct |
86 |
Correct |
619 ms |
8292 KB |
Output is correct |
87 |
Correct |
613 ms |
8192 KB |
Output is correct |
88 |
Correct |
2 ms |
3028 KB |
Output is correct |
89 |
Correct |
2 ms |
3028 KB |
Output is correct |
90 |
Correct |
12 ms |
4040 KB |
Output is correct |
91 |
Correct |
12 ms |
4028 KB |
Output is correct |
92 |
Correct |
80 ms |
6212 KB |
Output is correct |
93 |
Correct |
80 ms |
6312 KB |
Output is correct |
94 |
Correct |
259 ms |
7232 KB |
Output is correct |
95 |
Correct |
262 ms |
7316 KB |
Output is correct |
96 |
Correct |
458 ms |
7900 KB |
Output is correct |
97 |
Correct |
476 ms |
7816 KB |
Output is correct |
98 |
Correct |
218 ms |
7156 KB |
Output is correct |
99 |
Correct |
211 ms |
7112 KB |
Output is correct |
100 |
Correct |
210 ms |
7112 KB |
Output is correct |
101 |
Correct |
220 ms |
7192 KB |
Output is correct |
102 |
Correct |
212 ms |
7116 KB |
Output is correct |
103 |
Correct |
213 ms |
7056 KB |
Output is correct |
104 |
Correct |
241 ms |
7112 KB |
Output is correct |
105 |
Correct |
213 ms |
7184 KB |
Output is correct |