#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define sf scanf
#define pf printf
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
#define maxn 505
#define INF 1023456789
int n,k,a[maxn],b[maxn];
vector<ii> v;
ld memo[maxn];
int main(){
sf("%d%d",&n,&k);
for(int i=0;i<n;++i){
int x,y;
sf("%d%d",&x,&y);
if(y==-1)y=INF;
v.push_back({y,x});
}
sort(v.begin(),v.end());
int cnt=0;
for(int i=0;i<n;++i){
tie(b[i],a[i])=v[i];
if(b[i]!=INF)++cnt;
}
ld ans=INF;
for(int take=0;take<=min(k,cnt);++take){
for(int i=0;i<=n+1;++i){
memo[i]=INF;
}
memo[0]=0;
for(int pos=0;pos<n;++pos){
for(int vote=k-take;vote>=0;--vote){
ld ans=INF;
//case 1: take this
if(vote!=0)ans=min(ans,memo[vote-1]+(ld)a[pos]/(take+1));
//case 2: don't take this
//if this is one of the collaborators, add cost
if(pos-vote<take){
ans=min(ans,memo[vote]+(ld)b[pos]/(pos-vote+1));
}
else ans=min(ans,memo[vote]);
memo[vote]=ans;
}
}
ans=min(ans,memo[k-take]);
}
pf("%.15Lf\n",ans);
}
/*
7
5
393 646
375 666
374 676
320 635
288 668
284 758
333 702
1258.500000000000000
*/
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:20:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
20 | sf("%d%d",&n,&k);
| ^
Main.cpp:23:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | sf("%d%d",&x,&y);
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
3 ms |
312 KB |
Output is correct |
9 |
Correct |
2 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
3 ms |
312 KB |
Output is correct |
9 |
Correct |
2 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
39 ms |
212 KB |
Output is correct |
13 |
Correct |
38 ms |
300 KB |
Output is correct |
14 |
Correct |
37 ms |
308 KB |
Output is correct |
15 |
Correct |
222 ms |
212 KB |
Output is correct |
16 |
Correct |
220 ms |
212 KB |
Output is correct |
17 |
Correct |
107 ms |
296 KB |
Output is correct |
18 |
Correct |
442 ms |
212 KB |
Output is correct |
19 |
Correct |
383 ms |
292 KB |
Output is correct |
20 |
Correct |
146 ms |
296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
256 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
2 ms |
212 KB |
Output is correct |
46 |
Correct |
2 ms |
212 KB |
Output is correct |
47 |
Correct |
3 ms |
212 KB |
Output is correct |
48 |
Correct |
2 ms |
212 KB |
Output is correct |
49 |
Correct |
3 ms |
212 KB |
Output is correct |
50 |
Correct |
3 ms |
212 KB |
Output is correct |
51 |
Correct |
5 ms |
212 KB |
Output is correct |
52 |
Correct |
4 ms |
304 KB |
Output is correct |
53 |
Correct |
2 ms |
212 KB |
Output is correct |
54 |
Correct |
2 ms |
212 KB |
Output is correct |
55 |
Correct |
2 ms |
212 KB |
Output is correct |
56 |
Correct |
2 ms |
308 KB |
Output is correct |
57 |
Correct |
2 ms |
212 KB |
Output is correct |
58 |
Correct |
2 ms |
212 KB |
Output is correct |
59 |
Correct |
3 ms |
212 KB |
Output is correct |
60 |
Correct |
2 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
438 ms |
296 KB |
Output is correct |
2 |
Correct |
471 ms |
212 KB |
Output is correct |
3 |
Correct |
445 ms |
332 KB |
Output is correct |
4 |
Correct |
446 ms |
300 KB |
Output is correct |
5 |
Correct |
513 ms |
332 KB |
Output is correct |
6 |
Correct |
440 ms |
332 KB |
Output is correct |
7 |
Correct |
466 ms |
304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
3 ms |
312 KB |
Output is correct |
9 |
Correct |
2 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
39 ms |
212 KB |
Output is correct |
13 |
Correct |
38 ms |
300 KB |
Output is correct |
14 |
Correct |
37 ms |
308 KB |
Output is correct |
15 |
Correct |
222 ms |
212 KB |
Output is correct |
16 |
Correct |
220 ms |
212 KB |
Output is correct |
17 |
Correct |
107 ms |
296 KB |
Output is correct |
18 |
Correct |
442 ms |
212 KB |
Output is correct |
19 |
Correct |
383 ms |
292 KB |
Output is correct |
20 |
Correct |
146 ms |
296 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
0 ms |
212 KB |
Output is correct |
53 |
Correct |
0 ms |
212 KB |
Output is correct |
54 |
Correct |
0 ms |
212 KB |
Output is correct |
55 |
Correct |
0 ms |
212 KB |
Output is correct |
56 |
Correct |
0 ms |
212 KB |
Output is correct |
57 |
Correct |
0 ms |
212 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
0 ms |
212 KB |
Output is correct |
60 |
Correct |
0 ms |
212 KB |
Output is correct |
61 |
Correct |
0 ms |
212 KB |
Output is correct |
62 |
Correct |
1 ms |
256 KB |
Output is correct |
63 |
Correct |
1 ms |
212 KB |
Output is correct |
64 |
Correct |
1 ms |
212 KB |
Output is correct |
65 |
Correct |
2 ms |
212 KB |
Output is correct |
66 |
Correct |
2 ms |
212 KB |
Output is correct |
67 |
Correct |
3 ms |
212 KB |
Output is correct |
68 |
Correct |
2 ms |
212 KB |
Output is correct |
69 |
Correct |
3 ms |
212 KB |
Output is correct |
70 |
Correct |
3 ms |
212 KB |
Output is correct |
71 |
Correct |
5 ms |
212 KB |
Output is correct |
72 |
Correct |
4 ms |
304 KB |
Output is correct |
73 |
Correct |
2 ms |
212 KB |
Output is correct |
74 |
Correct |
2 ms |
212 KB |
Output is correct |
75 |
Correct |
2 ms |
212 KB |
Output is correct |
76 |
Correct |
2 ms |
308 KB |
Output is correct |
77 |
Correct |
2 ms |
212 KB |
Output is correct |
78 |
Correct |
2 ms |
212 KB |
Output is correct |
79 |
Correct |
3 ms |
212 KB |
Output is correct |
80 |
Correct |
2 ms |
212 KB |
Output is correct |
81 |
Correct |
438 ms |
296 KB |
Output is correct |
82 |
Correct |
471 ms |
212 KB |
Output is correct |
83 |
Correct |
445 ms |
332 KB |
Output is correct |
84 |
Correct |
446 ms |
300 KB |
Output is correct |
85 |
Correct |
513 ms |
332 KB |
Output is correct |
86 |
Correct |
440 ms |
332 KB |
Output is correct |
87 |
Correct |
466 ms |
304 KB |
Output is correct |
88 |
Correct |
5 ms |
212 KB |
Output is correct |
89 |
Correct |
6 ms |
304 KB |
Output is correct |
90 |
Correct |
28 ms |
212 KB |
Output is correct |
91 |
Correct |
30 ms |
308 KB |
Output is correct |
92 |
Correct |
113 ms |
212 KB |
Output is correct |
93 |
Correct |
130 ms |
308 KB |
Output is correct |
94 |
Correct |
276 ms |
296 KB |
Output is correct |
95 |
Correct |
249 ms |
304 KB |
Output is correct |
96 |
Correct |
346 ms |
300 KB |
Output is correct |
97 |
Correct |
384 ms |
300 KB |
Output is correct |
98 |
Correct |
243 ms |
296 KB |
Output is correct |
99 |
Correct |
214 ms |
332 KB |
Output is correct |
100 |
Correct |
218 ms |
300 KB |
Output is correct |
101 |
Correct |
263 ms |
300 KB |
Output is correct |
102 |
Correct |
225 ms |
300 KB |
Output is correct |
103 |
Correct |
216 ms |
296 KB |
Output is correct |
104 |
Correct |
213 ms |
316 KB |
Output is correct |
105 |
Correct |
272 ms |
300 KB |
Output is correct |