#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,popcnt,sse4")
#define ll long long
#define pll pair<ll,ll>
#define fs first
#define sc second
#define ld double
const ll inf = 1e12;
const ll mxn = 510;
pll arr[mxn];
ll N,K;
ld dp[mxn][mxn][mxn];
multiset<ll> st;
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>N>>K;
for(int i = 1;i<=N;i++)cin>>arr[i].sc>>arr[i].fs,arr[i].fs = (arr[i].fs == -1?inf:arr[i].fs);
sort(arr+1,arr+N+1);
for(auto &i:dp)for(auto &j:i)for(auto &k:j)k = inf;
for(int i = 0;i<=N;i++)dp[0][i][0] = 0;
for(int i = 1;i<=N;i++){
//for(int j = 0;j<=N;j++){
for(int j = 0;j<=N;j++){
for(int k = 0;k<=j;k++){
auto tmp = dp[i-1][j][k];
dp[i][j][k] = min(dp[i][j][k],tmp+arr[i].sc/ld(j+1));
dp[i][j][k+1] = min(dp[i][j][k+1],tmp+(arr[i].fs)/ld(k+1));
}
}
}
/*
for(int i = 0;i<=N;i++){
for(int j = 0;j<=i;j++)cout<<i<<' '<<j<<":"<<dp[i][j][j]<<endl;
}cout<<endl;
*/
ld ans = inf;
for(int i = N;i>K;i--){
st.insert(arr[i].sc);
}
for(int i = K;i>=0;i--){
ll sum = 0,C = K-i;
for(auto it = st.begin();C&&it != st.end();it++,C--){
sum += *it;
}
for(int j = 0;j<=i;j++){
ld tans = sum/ld(j+1)+dp[i][j][j];
ans = min(ans,tans);
}
st.insert(arr[i].sc);
}
cout<<fixed<<setprecision(20)<<ans<<'\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
149 ms |
1038580 KB |
Output is correct |
2 |
Correct |
136 ms |
1038924 KB |
Output is correct |
3 |
Correct |
132 ms |
1038604 KB |
Output is correct |
4 |
Correct |
130 ms |
1038636 KB |
Output is correct |
5 |
Correct |
281 ms |
1038800 KB |
Output is correct |
6 |
Correct |
291 ms |
1038800 KB |
Output is correct |
7 |
Correct |
275 ms |
1039188 KB |
Output is correct |
8 |
Correct |
273 ms |
1038648 KB |
Output is correct |
9 |
Correct |
283 ms |
1038804 KB |
Output is correct |
10 |
Correct |
295 ms |
1038804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
149 ms |
1038580 KB |
Output is correct |
2 |
Correct |
136 ms |
1038924 KB |
Output is correct |
3 |
Correct |
132 ms |
1038604 KB |
Output is correct |
4 |
Correct |
130 ms |
1038636 KB |
Output is correct |
5 |
Correct |
281 ms |
1038800 KB |
Output is correct |
6 |
Correct |
291 ms |
1038800 KB |
Output is correct |
7 |
Correct |
275 ms |
1039188 KB |
Output is correct |
8 |
Correct |
273 ms |
1038648 KB |
Output is correct |
9 |
Correct |
283 ms |
1038804 KB |
Output is correct |
10 |
Correct |
295 ms |
1038804 KB |
Output is correct |
11 |
Correct |
134 ms |
1038636 KB |
Output is correct |
12 |
Correct |
279 ms |
1038676 KB |
Output is correct |
13 |
Correct |
289 ms |
1038816 KB |
Output is correct |
14 |
Correct |
280 ms |
1038808 KB |
Output is correct |
15 |
Correct |
285 ms |
1038996 KB |
Output is correct |
16 |
Correct |
297 ms |
1038672 KB |
Output is correct |
17 |
Correct |
282 ms |
1038708 KB |
Output is correct |
18 |
Correct |
279 ms |
1038672 KB |
Output is correct |
19 |
Correct |
283 ms |
1038756 KB |
Output is correct |
20 |
Correct |
283 ms |
1038888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
131 ms |
1038676 KB |
Output is correct |
2 |
Correct |
132 ms |
1038676 KB |
Output is correct |
3 |
Correct |
131 ms |
1038672 KB |
Output is correct |
4 |
Correct |
162 ms |
1038756 KB |
Output is correct |
5 |
Correct |
132 ms |
1038676 KB |
Output is correct |
6 |
Correct |
131 ms |
1038676 KB |
Output is correct |
7 |
Correct |
134 ms |
1038892 KB |
Output is correct |
8 |
Correct |
130 ms |
1038676 KB |
Output is correct |
9 |
Correct |
132 ms |
1038788 KB |
Output is correct |
10 |
Correct |
129 ms |
1038708 KB |
Output is correct |
11 |
Correct |
134 ms |
1038564 KB |
Output is correct |
12 |
Correct |
131 ms |
1038712 KB |
Output is correct |
13 |
Correct |
139 ms |
1038552 KB |
Output is correct |
14 |
Correct |
134 ms |
1038556 KB |
Output is correct |
15 |
Correct |
138 ms |
1039068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
131 ms |
1038676 KB |
Output is correct |
2 |
Correct |
132 ms |
1038676 KB |
Output is correct |
3 |
Correct |
131 ms |
1038672 KB |
Output is correct |
4 |
Correct |
162 ms |
1038756 KB |
Output is correct |
5 |
Correct |
132 ms |
1038676 KB |
Output is correct |
6 |
Correct |
131 ms |
1038676 KB |
Output is correct |
7 |
Correct |
134 ms |
1038892 KB |
Output is correct |
8 |
Correct |
130 ms |
1038676 KB |
Output is correct |
9 |
Correct |
132 ms |
1038788 KB |
Output is correct |
10 |
Correct |
129 ms |
1038708 KB |
Output is correct |
11 |
Correct |
134 ms |
1038564 KB |
Output is correct |
12 |
Correct |
131 ms |
1038712 KB |
Output is correct |
13 |
Correct |
139 ms |
1038552 KB |
Output is correct |
14 |
Correct |
134 ms |
1038556 KB |
Output is correct |
15 |
Correct |
138 ms |
1039068 KB |
Output is correct |
16 |
Correct |
151 ms |
1038672 KB |
Output is correct |
17 |
Correct |
133 ms |
1038808 KB |
Output is correct |
18 |
Correct |
135 ms |
1038724 KB |
Output is correct |
19 |
Correct |
131 ms |
1038732 KB |
Output is correct |
20 |
Correct |
133 ms |
1038676 KB |
Output is correct |
21 |
Correct |
132 ms |
1038676 KB |
Output is correct |
22 |
Correct |
134 ms |
1038664 KB |
Output is correct |
23 |
Correct |
132 ms |
1038780 KB |
Output is correct |
24 |
Correct |
134 ms |
1038752 KB |
Output is correct |
25 |
Correct |
132 ms |
1038796 KB |
Output is correct |
26 |
Correct |
134 ms |
1038616 KB |
Output is correct |
27 |
Correct |
135 ms |
1038728 KB |
Output is correct |
28 |
Correct |
133 ms |
1038780 KB |
Output is correct |
29 |
Correct |
131 ms |
1038680 KB |
Output is correct |
30 |
Correct |
130 ms |
1038680 KB |
Output is correct |
31 |
Correct |
134 ms |
1038616 KB |
Output is correct |
32 |
Correct |
132 ms |
1038672 KB |
Output is correct |
33 |
Correct |
167 ms |
1038760 KB |
Output is correct |
34 |
Correct |
131 ms |
1038672 KB |
Output is correct |
35 |
Correct |
133 ms |
1038672 KB |
Output is correct |
36 |
Correct |
135 ms |
1038616 KB |
Output is correct |
37 |
Correct |
133 ms |
1038680 KB |
Output is correct |
38 |
Correct |
133 ms |
1038640 KB |
Output is correct |
39 |
Correct |
138 ms |
1038676 KB |
Output is correct |
40 |
Correct |
135 ms |
1038676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
131 ms |
1038676 KB |
Output is correct |
2 |
Correct |
132 ms |
1038676 KB |
Output is correct |
3 |
Correct |
131 ms |
1038672 KB |
Output is correct |
4 |
Correct |
162 ms |
1038756 KB |
Output is correct |
5 |
Correct |
132 ms |
1038676 KB |
Output is correct |
6 |
Correct |
131 ms |
1038676 KB |
Output is correct |
7 |
Correct |
134 ms |
1038892 KB |
Output is correct |
8 |
Correct |
130 ms |
1038676 KB |
Output is correct |
9 |
Correct |
132 ms |
1038788 KB |
Output is correct |
10 |
Correct |
129 ms |
1038708 KB |
Output is correct |
11 |
Correct |
134 ms |
1038564 KB |
Output is correct |
12 |
Correct |
131 ms |
1038712 KB |
Output is correct |
13 |
Correct |
139 ms |
1038552 KB |
Output is correct |
14 |
Correct |
134 ms |
1038556 KB |
Output is correct |
15 |
Correct |
138 ms |
1039068 KB |
Output is correct |
16 |
Correct |
151 ms |
1038672 KB |
Output is correct |
17 |
Correct |
133 ms |
1038808 KB |
Output is correct |
18 |
Correct |
135 ms |
1038724 KB |
Output is correct |
19 |
Correct |
131 ms |
1038732 KB |
Output is correct |
20 |
Correct |
133 ms |
1038676 KB |
Output is correct |
21 |
Correct |
132 ms |
1038676 KB |
Output is correct |
22 |
Correct |
134 ms |
1038664 KB |
Output is correct |
23 |
Correct |
132 ms |
1038780 KB |
Output is correct |
24 |
Correct |
134 ms |
1038752 KB |
Output is correct |
25 |
Correct |
132 ms |
1038796 KB |
Output is correct |
26 |
Correct |
134 ms |
1038616 KB |
Output is correct |
27 |
Correct |
135 ms |
1038728 KB |
Output is correct |
28 |
Correct |
133 ms |
1038780 KB |
Output is correct |
29 |
Correct |
131 ms |
1038680 KB |
Output is correct |
30 |
Correct |
130 ms |
1038680 KB |
Output is correct |
31 |
Correct |
134 ms |
1038616 KB |
Output is correct |
32 |
Correct |
132 ms |
1038672 KB |
Output is correct |
33 |
Correct |
167 ms |
1038760 KB |
Output is correct |
34 |
Correct |
131 ms |
1038672 KB |
Output is correct |
35 |
Correct |
133 ms |
1038672 KB |
Output is correct |
36 |
Correct |
135 ms |
1038616 KB |
Output is correct |
37 |
Correct |
133 ms |
1038680 KB |
Output is correct |
38 |
Correct |
133 ms |
1038640 KB |
Output is correct |
39 |
Correct |
138 ms |
1038676 KB |
Output is correct |
40 |
Correct |
135 ms |
1038676 KB |
Output is correct |
41 |
Correct |
134 ms |
1038900 KB |
Output is correct |
42 |
Correct |
137 ms |
1038560 KB |
Output is correct |
43 |
Correct |
135 ms |
1038648 KB |
Output is correct |
44 |
Correct |
134 ms |
1038672 KB |
Output is correct |
45 |
Correct |
133 ms |
1038668 KB |
Output is correct |
46 |
Correct |
134 ms |
1038672 KB |
Output is correct |
47 |
Correct |
138 ms |
1038800 KB |
Output is correct |
48 |
Correct |
136 ms |
1038668 KB |
Output is correct |
49 |
Correct |
135 ms |
1038672 KB |
Output is correct |
50 |
Correct |
136 ms |
1038676 KB |
Output is correct |
51 |
Correct |
153 ms |
1038772 KB |
Output is correct |
52 |
Correct |
134 ms |
1038676 KB |
Output is correct |
53 |
Correct |
135 ms |
1038680 KB |
Output is correct |
54 |
Correct |
137 ms |
1038960 KB |
Output is correct |
55 |
Correct |
135 ms |
1038660 KB |
Output is correct |
56 |
Correct |
143 ms |
1038676 KB |
Output is correct |
57 |
Correct |
146 ms |
1038632 KB |
Output is correct |
58 |
Correct |
139 ms |
1038928 KB |
Output is correct |
59 |
Correct |
140 ms |
1038676 KB |
Output is correct |
60 |
Correct |
136 ms |
1038676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
311 ms |
1038804 KB |
Output is correct |
2 |
Correct |
287 ms |
1038672 KB |
Output is correct |
3 |
Correct |
289 ms |
1038676 KB |
Output is correct |
4 |
Correct |
280 ms |
1038672 KB |
Output is correct |
5 |
Correct |
282 ms |
1038760 KB |
Output is correct |
6 |
Correct |
315 ms |
1038780 KB |
Output is correct |
7 |
Correct |
290 ms |
1038636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
149 ms |
1038580 KB |
Output is correct |
2 |
Correct |
136 ms |
1038924 KB |
Output is correct |
3 |
Correct |
132 ms |
1038604 KB |
Output is correct |
4 |
Correct |
130 ms |
1038636 KB |
Output is correct |
5 |
Correct |
281 ms |
1038800 KB |
Output is correct |
6 |
Correct |
291 ms |
1038800 KB |
Output is correct |
7 |
Correct |
275 ms |
1039188 KB |
Output is correct |
8 |
Correct |
273 ms |
1038648 KB |
Output is correct |
9 |
Correct |
283 ms |
1038804 KB |
Output is correct |
10 |
Correct |
295 ms |
1038804 KB |
Output is correct |
11 |
Correct |
134 ms |
1038636 KB |
Output is correct |
12 |
Correct |
279 ms |
1038676 KB |
Output is correct |
13 |
Correct |
289 ms |
1038816 KB |
Output is correct |
14 |
Correct |
280 ms |
1038808 KB |
Output is correct |
15 |
Correct |
285 ms |
1038996 KB |
Output is correct |
16 |
Correct |
297 ms |
1038672 KB |
Output is correct |
17 |
Correct |
282 ms |
1038708 KB |
Output is correct |
18 |
Correct |
279 ms |
1038672 KB |
Output is correct |
19 |
Correct |
283 ms |
1038756 KB |
Output is correct |
20 |
Correct |
283 ms |
1038888 KB |
Output is correct |
21 |
Correct |
131 ms |
1038676 KB |
Output is correct |
22 |
Correct |
132 ms |
1038676 KB |
Output is correct |
23 |
Correct |
131 ms |
1038672 KB |
Output is correct |
24 |
Correct |
162 ms |
1038756 KB |
Output is correct |
25 |
Correct |
132 ms |
1038676 KB |
Output is correct |
26 |
Correct |
131 ms |
1038676 KB |
Output is correct |
27 |
Correct |
134 ms |
1038892 KB |
Output is correct |
28 |
Correct |
130 ms |
1038676 KB |
Output is correct |
29 |
Correct |
132 ms |
1038788 KB |
Output is correct |
30 |
Correct |
129 ms |
1038708 KB |
Output is correct |
31 |
Correct |
134 ms |
1038564 KB |
Output is correct |
32 |
Correct |
131 ms |
1038712 KB |
Output is correct |
33 |
Correct |
139 ms |
1038552 KB |
Output is correct |
34 |
Correct |
134 ms |
1038556 KB |
Output is correct |
35 |
Correct |
138 ms |
1039068 KB |
Output is correct |
36 |
Correct |
151 ms |
1038672 KB |
Output is correct |
37 |
Correct |
133 ms |
1038808 KB |
Output is correct |
38 |
Correct |
135 ms |
1038724 KB |
Output is correct |
39 |
Correct |
131 ms |
1038732 KB |
Output is correct |
40 |
Correct |
133 ms |
1038676 KB |
Output is correct |
41 |
Correct |
132 ms |
1038676 KB |
Output is correct |
42 |
Correct |
134 ms |
1038664 KB |
Output is correct |
43 |
Correct |
132 ms |
1038780 KB |
Output is correct |
44 |
Correct |
134 ms |
1038752 KB |
Output is correct |
45 |
Correct |
132 ms |
1038796 KB |
Output is correct |
46 |
Correct |
134 ms |
1038616 KB |
Output is correct |
47 |
Correct |
135 ms |
1038728 KB |
Output is correct |
48 |
Correct |
133 ms |
1038780 KB |
Output is correct |
49 |
Correct |
131 ms |
1038680 KB |
Output is correct |
50 |
Correct |
130 ms |
1038680 KB |
Output is correct |
51 |
Correct |
134 ms |
1038616 KB |
Output is correct |
52 |
Correct |
132 ms |
1038672 KB |
Output is correct |
53 |
Correct |
167 ms |
1038760 KB |
Output is correct |
54 |
Correct |
131 ms |
1038672 KB |
Output is correct |
55 |
Correct |
133 ms |
1038672 KB |
Output is correct |
56 |
Correct |
135 ms |
1038616 KB |
Output is correct |
57 |
Correct |
133 ms |
1038680 KB |
Output is correct |
58 |
Correct |
133 ms |
1038640 KB |
Output is correct |
59 |
Correct |
138 ms |
1038676 KB |
Output is correct |
60 |
Correct |
135 ms |
1038676 KB |
Output is correct |
61 |
Correct |
134 ms |
1038900 KB |
Output is correct |
62 |
Correct |
137 ms |
1038560 KB |
Output is correct |
63 |
Correct |
135 ms |
1038648 KB |
Output is correct |
64 |
Correct |
134 ms |
1038672 KB |
Output is correct |
65 |
Correct |
133 ms |
1038668 KB |
Output is correct |
66 |
Correct |
134 ms |
1038672 KB |
Output is correct |
67 |
Correct |
138 ms |
1038800 KB |
Output is correct |
68 |
Correct |
136 ms |
1038668 KB |
Output is correct |
69 |
Correct |
135 ms |
1038672 KB |
Output is correct |
70 |
Correct |
136 ms |
1038676 KB |
Output is correct |
71 |
Correct |
153 ms |
1038772 KB |
Output is correct |
72 |
Correct |
134 ms |
1038676 KB |
Output is correct |
73 |
Correct |
135 ms |
1038680 KB |
Output is correct |
74 |
Correct |
137 ms |
1038960 KB |
Output is correct |
75 |
Correct |
135 ms |
1038660 KB |
Output is correct |
76 |
Correct |
143 ms |
1038676 KB |
Output is correct |
77 |
Correct |
146 ms |
1038632 KB |
Output is correct |
78 |
Correct |
139 ms |
1038928 KB |
Output is correct |
79 |
Correct |
140 ms |
1038676 KB |
Output is correct |
80 |
Correct |
136 ms |
1038676 KB |
Output is correct |
81 |
Correct |
311 ms |
1038804 KB |
Output is correct |
82 |
Correct |
287 ms |
1038672 KB |
Output is correct |
83 |
Correct |
289 ms |
1038676 KB |
Output is correct |
84 |
Correct |
280 ms |
1038672 KB |
Output is correct |
85 |
Correct |
282 ms |
1038760 KB |
Output is correct |
86 |
Correct |
315 ms |
1038780 KB |
Output is correct |
87 |
Correct |
290 ms |
1038636 KB |
Output is correct |
88 |
Correct |
298 ms |
1038804 KB |
Output is correct |
89 |
Correct |
277 ms |
1038740 KB |
Output is correct |
90 |
Correct |
279 ms |
1038808 KB |
Output is correct |
91 |
Correct |
281 ms |
1038812 KB |
Output is correct |
92 |
Correct |
281 ms |
1038804 KB |
Output is correct |
93 |
Correct |
293 ms |
1038808 KB |
Output is correct |
94 |
Correct |
282 ms |
1038800 KB |
Output is correct |
95 |
Correct |
288 ms |
1038864 KB |
Output is correct |
96 |
Correct |
281 ms |
1038672 KB |
Output is correct |
97 |
Correct |
280 ms |
1038676 KB |
Output is correct |
98 |
Correct |
277 ms |
1038784 KB |
Output is correct |
99 |
Correct |
288 ms |
1038672 KB |
Output is correct |
100 |
Correct |
303 ms |
1038804 KB |
Output is correct |
101 |
Correct |
305 ms |
1038812 KB |
Output is correct |
102 |
Correct |
276 ms |
1038804 KB |
Output is correct |
103 |
Correct |
315 ms |
1038676 KB |
Output is correct |
104 |
Correct |
282 ms |
1038584 KB |
Output is correct |
105 |
Correct |
294 ms |
1038808 KB |
Output is correct |