#include <bits/stdc++.h>
using namespace std ;
const int MAX = 500 + 10 ;
int arr[MAX] ;
int n , k ;
int a[MAX] , b[MAX] ;
long double dp[MAX][MAX] ;
int vis[MAX][MAX] ;
int val[MAX][MAX] ;
vector< pair<long double , long double> >vp ;
int m ;
long double solve(int idx , int cnt)
{
if(cnt == m)
return (1.00L * val[idx][k-idx] / (1.00L * m)) ;
if(idx == k)
return 1e9 ;
long double &ret = dp[idx][cnt] ;
if(vis[idx][cnt] == m)
return ret ;
vis[idx][cnt] = m ;
ret = solve(idx+1 , cnt+1) + (1.00L * vp[idx].second / (1.00L * cnt)) ;
ret = min(ret , solve(idx+1 , cnt) + (1.00L * vp[idx].first / m)) ;
return ret ;
}
int main()
{
memset(vis , -1 , sizeof(vis)) ;
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
cin>>n>>k ;
for(int i = 0 ; i < n ; ++i)
{
cin>>a[i]>>b[i] ;
if(b[i] == -1)
b[i] = 1e9 ;
}
for(int i = 0 ; i < n ; ++i)
vp.emplace_back(b[i] , a[i]) ;
sort(vp.begin() , vp.end()) ;
for(auto &p : vp)
swap(p.first , p.second) ;
vector<int>v ;
for(int i = n-1 ; i >= 0 ; --i)
{
v.push_back(vp[i].first) ;
sort(v.begin() , v.end()) ;
val[i][0] = 0 ;
for(int j = 1 ; j <= n-i ; ++j)
val[i][j] = val[i][j-1] + v[j-1] ;
}
long double ans = 1e18 ;
for(int i = 1 ; i <= k ; ++i)
{
m = i ;
ans = min(ans , solve(0 , 1)) ;
}
return cout<<fixed<<setprecision(12)<<ans<<"\n" , 0 ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1236 KB |
Output is correct |
2 |
Correct |
1 ms |
1364 KB |
Output is correct |
3 |
Correct |
1 ms |
1364 KB |
Output is correct |
4 |
Correct |
1 ms |
1364 KB |
Output is correct |
5 |
Correct |
5 ms |
2516 KB |
Output is correct |
6 |
Correct |
14 ms |
3028 KB |
Output is correct |
7 |
Correct |
78 ms |
3768 KB |
Output is correct |
8 |
Correct |
277 ms |
4760 KB |
Output is correct |
9 |
Correct |
692 ms |
5796 KB |
Output is correct |
10 |
Correct |
216 ms |
4640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1236 KB |
Output is correct |
2 |
Correct |
1 ms |
1364 KB |
Output is correct |
3 |
Correct |
1 ms |
1364 KB |
Output is correct |
4 |
Correct |
1 ms |
1364 KB |
Output is correct |
5 |
Correct |
5 ms |
2516 KB |
Output is correct |
6 |
Correct |
14 ms |
3028 KB |
Output is correct |
7 |
Correct |
78 ms |
3768 KB |
Output is correct |
8 |
Correct |
277 ms |
4760 KB |
Output is correct |
9 |
Correct |
692 ms |
5796 KB |
Output is correct |
10 |
Correct |
216 ms |
4640 KB |
Output is correct |
11 |
Correct |
1 ms |
1236 KB |
Output is correct |
12 |
Correct |
25 ms |
3144 KB |
Output is correct |
13 |
Correct |
23 ms |
3196 KB |
Output is correct |
14 |
Correct |
20 ms |
3192 KB |
Output is correct |
15 |
Correct |
223 ms |
4656 KB |
Output is correct |
16 |
Correct |
211 ms |
4548 KB |
Output is correct |
17 |
Correct |
237 ms |
4684 KB |
Output is correct |
18 |
Correct |
626 ms |
5880 KB |
Output is correct |
19 |
Correct |
645 ms |
5876 KB |
Output is correct |
20 |
Correct |
658 ms |
5784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1360 KB |
Output is correct |
2 |
Correct |
1 ms |
1364 KB |
Output is correct |
3 |
Correct |
1 ms |
1364 KB |
Output is correct |
4 |
Correct |
1 ms |
1364 KB |
Output is correct |
5 |
Correct |
1 ms |
1364 KB |
Output is correct |
6 |
Correct |
1 ms |
1364 KB |
Output is correct |
7 |
Correct |
1 ms |
1364 KB |
Output is correct |
8 |
Correct |
1 ms |
1352 KB |
Output is correct |
9 |
Correct |
1 ms |
1364 KB |
Output is correct |
10 |
Correct |
1 ms |
1364 KB |
Output is correct |
11 |
Correct |
1 ms |
1364 KB |
Output is correct |
12 |
Correct |
1 ms |
1356 KB |
Output is correct |
13 |
Correct |
1 ms |
1364 KB |
Output is correct |
14 |
Correct |
1 ms |
1364 KB |
Output is correct |
15 |
Correct |
1 ms |
1352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1360 KB |
Output is correct |
2 |
Correct |
1 ms |
1364 KB |
Output is correct |
3 |
Correct |
1 ms |
1364 KB |
Output is correct |
4 |
Correct |
1 ms |
1364 KB |
Output is correct |
5 |
Correct |
1 ms |
1364 KB |
Output is correct |
6 |
Correct |
1 ms |
1364 KB |
Output is correct |
7 |
Correct |
1 ms |
1364 KB |
Output is correct |
8 |
Correct |
1 ms |
1352 KB |
Output is correct |
9 |
Correct |
1 ms |
1364 KB |
Output is correct |
10 |
Correct |
1 ms |
1364 KB |
Output is correct |
11 |
Correct |
1 ms |
1364 KB |
Output is correct |
12 |
Correct |
1 ms |
1356 KB |
Output is correct |
13 |
Correct |
1 ms |
1364 KB |
Output is correct |
14 |
Correct |
1 ms |
1364 KB |
Output is correct |
15 |
Correct |
1 ms |
1352 KB |
Output is correct |
16 |
Correct |
1 ms |
1364 KB |
Output is correct |
17 |
Correct |
1 ms |
1364 KB |
Output is correct |
18 |
Correct |
1 ms |
1356 KB |
Output is correct |
19 |
Correct |
1 ms |
1364 KB |
Output is correct |
20 |
Correct |
1 ms |
1364 KB |
Output is correct |
21 |
Correct |
1 ms |
1360 KB |
Output is correct |
22 |
Correct |
1 ms |
1364 KB |
Output is correct |
23 |
Correct |
1 ms |
1360 KB |
Output is correct |
24 |
Correct |
1 ms |
1364 KB |
Output is correct |
25 |
Correct |
1 ms |
1364 KB |
Output is correct |
26 |
Correct |
1 ms |
1364 KB |
Output is correct |
27 |
Correct |
1 ms |
1364 KB |
Output is correct |
28 |
Correct |
1 ms |
1364 KB |
Output is correct |
29 |
Correct |
1 ms |
1356 KB |
Output is correct |
30 |
Correct |
1 ms |
1356 KB |
Output is correct |
31 |
Correct |
1 ms |
1356 KB |
Output is correct |
32 |
Correct |
1 ms |
1364 KB |
Output is correct |
33 |
Correct |
1 ms |
1360 KB |
Output is correct |
34 |
Correct |
1 ms |
1364 KB |
Output is correct |
35 |
Correct |
1 ms |
1364 KB |
Output is correct |
36 |
Correct |
1 ms |
1356 KB |
Output is correct |
37 |
Correct |
1 ms |
1348 KB |
Output is correct |
38 |
Correct |
1 ms |
1364 KB |
Output is correct |
39 |
Correct |
1 ms |
1364 KB |
Output is correct |
40 |
Correct |
1 ms |
1364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1360 KB |
Output is correct |
2 |
Correct |
1 ms |
1364 KB |
Output is correct |
3 |
Correct |
1 ms |
1364 KB |
Output is correct |
4 |
Correct |
1 ms |
1364 KB |
Output is correct |
5 |
Correct |
1 ms |
1364 KB |
Output is correct |
6 |
Correct |
1 ms |
1364 KB |
Output is correct |
7 |
Correct |
1 ms |
1364 KB |
Output is correct |
8 |
Correct |
1 ms |
1352 KB |
Output is correct |
9 |
Correct |
1 ms |
1364 KB |
Output is correct |
10 |
Correct |
1 ms |
1364 KB |
Output is correct |
11 |
Correct |
1 ms |
1364 KB |
Output is correct |
12 |
Correct |
1 ms |
1356 KB |
Output is correct |
13 |
Correct |
1 ms |
1364 KB |
Output is correct |
14 |
Correct |
1 ms |
1364 KB |
Output is correct |
15 |
Correct |
1 ms |
1352 KB |
Output is correct |
16 |
Correct |
1 ms |
1364 KB |
Output is correct |
17 |
Correct |
1 ms |
1364 KB |
Output is correct |
18 |
Correct |
1 ms |
1356 KB |
Output is correct |
19 |
Correct |
1 ms |
1364 KB |
Output is correct |
20 |
Correct |
1 ms |
1364 KB |
Output is correct |
21 |
Correct |
1 ms |
1360 KB |
Output is correct |
22 |
Correct |
1 ms |
1364 KB |
Output is correct |
23 |
Correct |
1 ms |
1360 KB |
Output is correct |
24 |
Correct |
1 ms |
1364 KB |
Output is correct |
25 |
Correct |
1 ms |
1364 KB |
Output is correct |
26 |
Correct |
1 ms |
1364 KB |
Output is correct |
27 |
Correct |
1 ms |
1364 KB |
Output is correct |
28 |
Correct |
1 ms |
1364 KB |
Output is correct |
29 |
Correct |
1 ms |
1356 KB |
Output is correct |
30 |
Correct |
1 ms |
1356 KB |
Output is correct |
31 |
Correct |
1 ms |
1356 KB |
Output is correct |
32 |
Correct |
1 ms |
1364 KB |
Output is correct |
33 |
Correct |
1 ms |
1360 KB |
Output is correct |
34 |
Correct |
1 ms |
1364 KB |
Output is correct |
35 |
Correct |
1 ms |
1364 KB |
Output is correct |
36 |
Correct |
1 ms |
1356 KB |
Output is correct |
37 |
Correct |
1 ms |
1348 KB |
Output is correct |
38 |
Correct |
1 ms |
1364 KB |
Output is correct |
39 |
Correct |
1 ms |
1364 KB |
Output is correct |
40 |
Correct |
1 ms |
1364 KB |
Output is correct |
41 |
Correct |
1 ms |
1492 KB |
Output is correct |
42 |
Correct |
1 ms |
1608 KB |
Output is correct |
43 |
Correct |
1 ms |
1620 KB |
Output is correct |
44 |
Correct |
1 ms |
1620 KB |
Output is correct |
45 |
Correct |
2 ms |
1748 KB |
Output is correct |
46 |
Correct |
2 ms |
1740 KB |
Output is correct |
47 |
Correct |
2 ms |
1876 KB |
Output is correct |
48 |
Correct |
2 ms |
1868 KB |
Output is correct |
49 |
Correct |
6 ms |
1996 KB |
Output is correct |
50 |
Correct |
5 ms |
1876 KB |
Output is correct |
51 |
Correct |
6 ms |
2132 KB |
Output is correct |
52 |
Correct |
6 ms |
2132 KB |
Output is correct |
53 |
Correct |
2 ms |
1876 KB |
Output is correct |
54 |
Correct |
2 ms |
1872 KB |
Output is correct |
55 |
Correct |
2 ms |
1876 KB |
Output is correct |
56 |
Correct |
2 ms |
1876 KB |
Output is correct |
57 |
Correct |
3 ms |
1876 KB |
Output is correct |
58 |
Correct |
2 ms |
1876 KB |
Output is correct |
59 |
Correct |
3 ms |
1876 KB |
Output is correct |
60 |
Correct |
2 ms |
1872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
602 ms |
5980 KB |
Output is correct |
2 |
Correct |
611 ms |
5880 KB |
Output is correct |
3 |
Correct |
617 ms |
5872 KB |
Output is correct |
4 |
Correct |
625 ms |
5880 KB |
Output is correct |
5 |
Correct |
625 ms |
5880 KB |
Output is correct |
6 |
Correct |
640 ms |
5876 KB |
Output is correct |
7 |
Correct |
599 ms |
5836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1236 KB |
Output is correct |
2 |
Correct |
1 ms |
1364 KB |
Output is correct |
3 |
Correct |
1 ms |
1364 KB |
Output is correct |
4 |
Correct |
1 ms |
1364 KB |
Output is correct |
5 |
Correct |
5 ms |
2516 KB |
Output is correct |
6 |
Correct |
14 ms |
3028 KB |
Output is correct |
7 |
Correct |
78 ms |
3768 KB |
Output is correct |
8 |
Correct |
277 ms |
4760 KB |
Output is correct |
9 |
Correct |
692 ms |
5796 KB |
Output is correct |
10 |
Correct |
216 ms |
4640 KB |
Output is correct |
11 |
Correct |
1 ms |
1236 KB |
Output is correct |
12 |
Correct |
25 ms |
3144 KB |
Output is correct |
13 |
Correct |
23 ms |
3196 KB |
Output is correct |
14 |
Correct |
20 ms |
3192 KB |
Output is correct |
15 |
Correct |
223 ms |
4656 KB |
Output is correct |
16 |
Correct |
211 ms |
4548 KB |
Output is correct |
17 |
Correct |
237 ms |
4684 KB |
Output is correct |
18 |
Correct |
626 ms |
5880 KB |
Output is correct |
19 |
Correct |
645 ms |
5876 KB |
Output is correct |
20 |
Correct |
658 ms |
5784 KB |
Output is correct |
21 |
Correct |
1 ms |
1360 KB |
Output is correct |
22 |
Correct |
1 ms |
1364 KB |
Output is correct |
23 |
Correct |
1 ms |
1364 KB |
Output is correct |
24 |
Correct |
1 ms |
1364 KB |
Output is correct |
25 |
Correct |
1 ms |
1364 KB |
Output is correct |
26 |
Correct |
1 ms |
1364 KB |
Output is correct |
27 |
Correct |
1 ms |
1364 KB |
Output is correct |
28 |
Correct |
1 ms |
1352 KB |
Output is correct |
29 |
Correct |
1 ms |
1364 KB |
Output is correct |
30 |
Correct |
1 ms |
1364 KB |
Output is correct |
31 |
Correct |
1 ms |
1364 KB |
Output is correct |
32 |
Correct |
1 ms |
1356 KB |
Output is correct |
33 |
Correct |
1 ms |
1364 KB |
Output is correct |
34 |
Correct |
1 ms |
1364 KB |
Output is correct |
35 |
Correct |
1 ms |
1352 KB |
Output is correct |
36 |
Correct |
1 ms |
1364 KB |
Output is correct |
37 |
Correct |
1 ms |
1364 KB |
Output is correct |
38 |
Correct |
1 ms |
1356 KB |
Output is correct |
39 |
Correct |
1 ms |
1364 KB |
Output is correct |
40 |
Correct |
1 ms |
1364 KB |
Output is correct |
41 |
Correct |
1 ms |
1360 KB |
Output is correct |
42 |
Correct |
1 ms |
1364 KB |
Output is correct |
43 |
Correct |
1 ms |
1360 KB |
Output is correct |
44 |
Correct |
1 ms |
1364 KB |
Output is correct |
45 |
Correct |
1 ms |
1364 KB |
Output is correct |
46 |
Correct |
1 ms |
1364 KB |
Output is correct |
47 |
Correct |
1 ms |
1364 KB |
Output is correct |
48 |
Correct |
1 ms |
1364 KB |
Output is correct |
49 |
Correct |
1 ms |
1356 KB |
Output is correct |
50 |
Correct |
1 ms |
1356 KB |
Output is correct |
51 |
Correct |
1 ms |
1356 KB |
Output is correct |
52 |
Correct |
1 ms |
1364 KB |
Output is correct |
53 |
Correct |
1 ms |
1360 KB |
Output is correct |
54 |
Correct |
1 ms |
1364 KB |
Output is correct |
55 |
Correct |
1 ms |
1364 KB |
Output is correct |
56 |
Correct |
1 ms |
1356 KB |
Output is correct |
57 |
Correct |
1 ms |
1348 KB |
Output is correct |
58 |
Correct |
1 ms |
1364 KB |
Output is correct |
59 |
Correct |
1 ms |
1364 KB |
Output is correct |
60 |
Correct |
1 ms |
1364 KB |
Output is correct |
61 |
Correct |
1 ms |
1492 KB |
Output is correct |
62 |
Correct |
1 ms |
1608 KB |
Output is correct |
63 |
Correct |
1 ms |
1620 KB |
Output is correct |
64 |
Correct |
1 ms |
1620 KB |
Output is correct |
65 |
Correct |
2 ms |
1748 KB |
Output is correct |
66 |
Correct |
2 ms |
1740 KB |
Output is correct |
67 |
Correct |
2 ms |
1876 KB |
Output is correct |
68 |
Correct |
2 ms |
1868 KB |
Output is correct |
69 |
Correct |
6 ms |
1996 KB |
Output is correct |
70 |
Correct |
5 ms |
1876 KB |
Output is correct |
71 |
Correct |
6 ms |
2132 KB |
Output is correct |
72 |
Correct |
6 ms |
2132 KB |
Output is correct |
73 |
Correct |
2 ms |
1876 KB |
Output is correct |
74 |
Correct |
2 ms |
1872 KB |
Output is correct |
75 |
Correct |
2 ms |
1876 KB |
Output is correct |
76 |
Correct |
2 ms |
1876 KB |
Output is correct |
77 |
Correct |
3 ms |
1876 KB |
Output is correct |
78 |
Correct |
2 ms |
1876 KB |
Output is correct |
79 |
Correct |
3 ms |
1876 KB |
Output is correct |
80 |
Correct |
2 ms |
1872 KB |
Output is correct |
81 |
Correct |
602 ms |
5980 KB |
Output is correct |
82 |
Correct |
611 ms |
5880 KB |
Output is correct |
83 |
Correct |
617 ms |
5872 KB |
Output is correct |
84 |
Correct |
625 ms |
5880 KB |
Output is correct |
85 |
Correct |
625 ms |
5880 KB |
Output is correct |
86 |
Correct |
640 ms |
5876 KB |
Output is correct |
87 |
Correct |
599 ms |
5836 KB |
Output is correct |
88 |
Correct |
5 ms |
2516 KB |
Output is correct |
89 |
Correct |
5 ms |
2508 KB |
Output is correct |
90 |
Correct |
13 ms |
3028 KB |
Output is correct |
91 |
Correct |
14 ms |
3156 KB |
Output is correct |
92 |
Correct |
79 ms |
3752 KB |
Output is correct |
93 |
Correct |
77 ms |
3856 KB |
Output is correct |
94 |
Correct |
267 ms |
4788 KB |
Output is correct |
95 |
Correct |
259 ms |
4876 KB |
Output is correct |
96 |
Correct |
431 ms |
5404 KB |
Output is correct |
97 |
Correct |
464 ms |
5476 KB |
Output is correct |
98 |
Correct |
204 ms |
4632 KB |
Output is correct |
99 |
Correct |
205 ms |
4576 KB |
Output is correct |
100 |
Correct |
219 ms |
4692 KB |
Output is correct |
101 |
Correct |
207 ms |
4672 KB |
Output is correct |
102 |
Correct |
205 ms |
4556 KB |
Output is correct |
103 |
Correct |
221 ms |
4816 KB |
Output is correct |
104 |
Correct |
217 ms |
4564 KB |
Output is correct |
105 |
Correct |
202 ms |
4628 KB |
Output is correct |