//#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#define y2 y_2
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
const ll inf=1e18;
mt19937 rnd(time(NULL));
const ll mod=998244353;
const int N=510;
const int Lg=16;
ld pref[N][N];
ld suf[N][N];
ll sum[N];
void solve(){
int n,k;cin>>n>>k;
vector<pair<ll,ll> >v;
for (int i=1;i<=n;i++){
ll a,b;cin>>a>>b;
if (b==-1) b=inf;
v.push_back({b,a});
}
sort(v.begin(),v.end());
ld res=0;
vector<ll>u;
for (int i=n-1;i>=0;i--){
sum[i]=0;
for (int j=0;j<k-i-1;j++) sum[i]+=u[j];
u.push_back(v[i].second);
sort(u.begin(),u.end());
}
for (int i=0;i<k;i++) res+=u[i];
for (int l=0;l<k;l++){
for (int i=0;i<=n+1;i++){
for (int j=0;j<=n+1;j++){
pref[i][j]=suf[i][j]=inf;
}
}
pref[0][0]=0.0;
for (int i=0;i<n;i++){
for (int j=0;j<=i;j++){
pref[i+1][j]=min(pref[i+1][j],pref[i][j]+(ld)v[i].second/(l+1.0));
if (v[i].first<inf) pref[i+1][j+1]=min(pref[i+1][j+1],pref[i][j]+(ld)v[i].first/(j+1.0));
}
}
for (int i=n-1;i>=0;i--){
ld cur=pref[i+1][l];
cur+=(ld)sum[i]/(l+1.0);
res=min(res,cur);
}
}
cout<<setprecision(10)<<fixed<<res<<endl;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int tt=1;
// cin>>tt;
while (tt--){
solve();
}
return 0;
}
/**
3
5 2 7 3 1 6 8 4
**/
# |
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 |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
186 ms |
8352 KB |
Output is correct |
6 |
Correct |
446 ms |
8352 KB |
Output is correct |
7 |
Correct |
887 ms |
8396 KB |
Output is correct |
8 |
Correct |
1312 ms |
8348 KB |
Output is correct |
9 |
Correct |
1782 ms |
8352 KB |
Output is correct |
10 |
Correct |
1251 ms |
8356 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 |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
186 ms |
8352 KB |
Output is correct |
6 |
Correct |
446 ms |
8352 KB |
Output is correct |
7 |
Correct |
887 ms |
8396 KB |
Output is correct |
8 |
Correct |
1312 ms |
8348 KB |
Output is correct |
9 |
Correct |
1782 ms |
8352 KB |
Output is correct |
10 |
Correct |
1251 ms |
8356 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
664 ms |
8352 KB |
Output is correct |
13 |
Correct |
577 ms |
8356 KB |
Output is correct |
14 |
Correct |
536 ms |
8356 KB |
Output is correct |
15 |
Correct |
1502 ms |
8396 KB |
Output is correct |
16 |
Correct |
1331 ms |
8396 KB |
Output is correct |
17 |
Correct |
1239 ms |
8356 KB |
Output is correct |
18 |
Correct |
2157 ms |
8356 KB |
Output is correct |
19 |
Correct |
1888 ms |
8364 KB |
Output is correct |
20 |
Correct |
1777 ms |
8364 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 |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
340 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 |
0 ms |
340 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 |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
340 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 |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
468 KB |
Output is correct |
17 |
Correct |
0 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
0 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 |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
0 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
0 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
0 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
0 ms |
468 KB |
Output is correct |
34 |
Correct |
0 ms |
468 KB |
Output is correct |
35 |
Correct |
0 ms |
468 KB |
Output is correct |
36 |
Correct |
1 ms |
468 KB |
Output is correct |
37 |
Correct |
1 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 |
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 |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
340 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 |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
468 KB |
Output is correct |
17 |
Correct |
0 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
0 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 |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
0 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
0 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
0 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
0 ms |
468 KB |
Output is correct |
34 |
Correct |
0 ms |
468 KB |
Output is correct |
35 |
Correct |
0 ms |
468 KB |
Output is correct |
36 |
Correct |
1 ms |
468 KB |
Output is correct |
37 |
Correct |
1 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 |
1 ms |
468 KB |
Output is correct |
41 |
Correct |
4 ms |
1492 KB |
Output is correct |
42 |
Correct |
4 ms |
1556 KB |
Output is correct |
43 |
Correct |
7 ms |
1492 KB |
Output is correct |
44 |
Correct |
6 ms |
1560 KB |
Output is correct |
45 |
Correct |
10 ms |
1492 KB |
Output is correct |
46 |
Correct |
9 ms |
1492 KB |
Output is correct |
47 |
Correct |
13 ms |
1564 KB |
Output is correct |
48 |
Correct |
13 ms |
1492 KB |
Output is correct |
49 |
Correct |
17 ms |
1492 KB |
Output is correct |
50 |
Correct |
15 ms |
1564 KB |
Output is correct |
51 |
Correct |
21 ms |
1564 KB |
Output is correct |
52 |
Correct |
19 ms |
1492 KB |
Output is correct |
53 |
Correct |
13 ms |
1556 KB |
Output is correct |
54 |
Correct |
13 ms |
1492 KB |
Output is correct |
55 |
Correct |
13 ms |
1560 KB |
Output is correct |
56 |
Correct |
13 ms |
1560 KB |
Output is correct |
57 |
Correct |
12 ms |
1492 KB |
Output is correct |
58 |
Correct |
13 ms |
1556 KB |
Output is correct |
59 |
Correct |
13 ms |
1560 KB |
Output is correct |
60 |
Correct |
12 ms |
1560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2173 ms |
8352 KB |
Output is correct |
2 |
Correct |
2210 ms |
8356 KB |
Output is correct |
3 |
Correct |
2167 ms |
8360 KB |
Output is correct |
4 |
Correct |
2164 ms |
8364 KB |
Output is correct |
5 |
Correct |
2197 ms |
8360 KB |
Output is correct |
6 |
Correct |
2207 ms |
8364 KB |
Output is correct |
7 |
Correct |
2155 ms |
8360 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 |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
186 ms |
8352 KB |
Output is correct |
6 |
Correct |
446 ms |
8352 KB |
Output is correct |
7 |
Correct |
887 ms |
8396 KB |
Output is correct |
8 |
Correct |
1312 ms |
8348 KB |
Output is correct |
9 |
Correct |
1782 ms |
8352 KB |
Output is correct |
10 |
Correct |
1251 ms |
8356 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
664 ms |
8352 KB |
Output is correct |
13 |
Correct |
577 ms |
8356 KB |
Output is correct |
14 |
Correct |
536 ms |
8356 KB |
Output is correct |
15 |
Correct |
1502 ms |
8396 KB |
Output is correct |
16 |
Correct |
1331 ms |
8396 KB |
Output is correct |
17 |
Correct |
1239 ms |
8356 KB |
Output is correct |
18 |
Correct |
2157 ms |
8356 KB |
Output is correct |
19 |
Correct |
1888 ms |
8364 KB |
Output is correct |
20 |
Correct |
1777 ms |
8364 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
1 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 |
1 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 |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 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 |
0 ms |
340 KB |
Output is correct |
36 |
Correct |
0 ms |
468 KB |
Output is correct |
37 |
Correct |
0 ms |
468 KB |
Output is correct |
38 |
Correct |
1 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 |
468 KB |
Output is correct |
42 |
Correct |
1 ms |
468 KB |
Output is correct |
43 |
Correct |
0 ms |
468 KB |
Output is correct |
44 |
Correct |
1 ms |
468 KB |
Output is correct |
45 |
Correct |
1 ms |
468 KB |
Output is correct |
46 |
Correct |
1 ms |
468 KB |
Output is correct |
47 |
Correct |
1 ms |
468 KB |
Output is correct |
48 |
Correct |
0 ms |
468 KB |
Output is correct |
49 |
Correct |
1 ms |
468 KB |
Output is correct |
50 |
Correct |
0 ms |
468 KB |
Output is correct |
51 |
Correct |
1 ms |
468 KB |
Output is correct |
52 |
Correct |
1 ms |
468 KB |
Output is correct |
53 |
Correct |
0 ms |
468 KB |
Output is correct |
54 |
Correct |
0 ms |
468 KB |
Output is correct |
55 |
Correct |
0 ms |
468 KB |
Output is correct |
56 |
Correct |
1 ms |
468 KB |
Output is correct |
57 |
Correct |
1 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 |
1 ms |
468 KB |
Output is correct |
61 |
Correct |
4 ms |
1492 KB |
Output is correct |
62 |
Correct |
4 ms |
1556 KB |
Output is correct |
63 |
Correct |
7 ms |
1492 KB |
Output is correct |
64 |
Correct |
6 ms |
1560 KB |
Output is correct |
65 |
Correct |
10 ms |
1492 KB |
Output is correct |
66 |
Correct |
9 ms |
1492 KB |
Output is correct |
67 |
Correct |
13 ms |
1564 KB |
Output is correct |
68 |
Correct |
13 ms |
1492 KB |
Output is correct |
69 |
Correct |
17 ms |
1492 KB |
Output is correct |
70 |
Correct |
15 ms |
1564 KB |
Output is correct |
71 |
Correct |
21 ms |
1564 KB |
Output is correct |
72 |
Correct |
19 ms |
1492 KB |
Output is correct |
73 |
Correct |
13 ms |
1556 KB |
Output is correct |
74 |
Correct |
13 ms |
1492 KB |
Output is correct |
75 |
Correct |
13 ms |
1560 KB |
Output is correct |
76 |
Correct |
13 ms |
1560 KB |
Output is correct |
77 |
Correct |
12 ms |
1492 KB |
Output is correct |
78 |
Correct |
13 ms |
1556 KB |
Output is correct |
79 |
Correct |
13 ms |
1560 KB |
Output is correct |
80 |
Correct |
12 ms |
1560 KB |
Output is correct |
81 |
Correct |
2173 ms |
8352 KB |
Output is correct |
82 |
Correct |
2210 ms |
8356 KB |
Output is correct |
83 |
Correct |
2167 ms |
8360 KB |
Output is correct |
84 |
Correct |
2164 ms |
8364 KB |
Output is correct |
85 |
Correct |
2197 ms |
8360 KB |
Output is correct |
86 |
Correct |
2207 ms |
8364 KB |
Output is correct |
87 |
Correct |
2155 ms |
8360 KB |
Output is correct |
88 |
Correct |
225 ms |
8276 KB |
Output is correct |
89 |
Correct |
224 ms |
8360 KB |
Output is correct |
90 |
Correct |
548 ms |
8356 KB |
Output is correct |
91 |
Correct |
548 ms |
8376 KB |
Output is correct |
92 |
Correct |
1081 ms |
8360 KB |
Output is correct |
93 |
Correct |
1087 ms |
8368 KB |
Output is correct |
94 |
Correct |
1614 ms |
8396 KB |
Output is correct |
95 |
Correct |
1605 ms |
8360 KB |
Output is correct |
96 |
Correct |
1929 ms |
8356 KB |
Output is correct |
97 |
Correct |
1923 ms |
8364 KB |
Output is correct |
98 |
Correct |
1507 ms |
8368 KB |
Output is correct |
99 |
Correct |
1507 ms |
8396 KB |
Output is correct |
100 |
Correct |
1499 ms |
8276 KB |
Output is correct |
101 |
Correct |
1534 ms |
8356 KB |
Output is correct |
102 |
Correct |
1511 ms |
8356 KB |
Output is correct |
103 |
Correct |
1502 ms |
8360 KB |
Output is correct |
104 |
Correct |
1509 ms |
8364 KB |
Output is correct |
105 |
Correct |
1507 ms |
8360 KB |
Output is correct |