#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
#define debug(y) cout<<y,exit(0)
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 500 + 9;
const ll inf = 1e18 + 7;
ld ans = inf*1.0,dp[N][N];
ll n,k,collab;
LL a[N];
bool lf(LL x,LL y){
return x.sc < y.sc;
}
ld cal(ll mid){
for (ll i = 1;i <= n;i++)
for (ll j = 0;j <= i;j++){
dp[i][j] = inf;
if (i - j - 1 >= mid) dp[i][j] = dp[i - 1][j];
else dp[i][j] = dp[i - 1][j] + (ld)a[i].sc/((ld)i - j);
if (j) dp[i][j] = min(dp[i][j],dp[i - 1][j - 1] + (ld)a[i].fs/((ld)mid + 1));
}
ld tmp = inf;
for (ll i = k - mid;i <= n;i++)
if (n - i >= mid) tmp = min(tmp,dp[n][i]);
return tmp;
}
int main(){
ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define task "test"
if (fopen(task".inp","r")){
freopen(task".inp","r",stdin);
//freopen(task".out","w",stdout);
}
cin>>n>>k;
for (ll i = 1;i <= n;i++){
cin>>a[i].fs>>a[i].sc;
collab += (a[i].sc != -1);
if (a[i].sc == -1) a[i].sc = inf;
}
sort(a + 1,a + n + 1,lf);
ll l = 0,h = min(k,collab);
while(l <= h){
ll mid = (l + h)/2;
if (cal(mid) <= cal(mid + 1)) h = mid - 1;
else l = mid + 1;
}
//debug(h);
cout<<fixed<<setprecision(6)<<cal(l);
}
/// be confident
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
38 | freopen(task".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
6 ms |
3824 KB |
Output is correct |
6 |
Correct |
6 ms |
3796 KB |
Output is correct |
7 |
Correct |
6 ms |
3824 KB |
Output is correct |
8 |
Correct |
6 ms |
3820 KB |
Output is correct |
9 |
Correct |
5 ms |
3796 KB |
Output is correct |
10 |
Correct |
6 ms |
3796 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 |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
6 ms |
3824 KB |
Output is correct |
6 |
Correct |
6 ms |
3796 KB |
Output is correct |
7 |
Correct |
6 ms |
3824 KB |
Output is correct |
8 |
Correct |
6 ms |
3820 KB |
Output is correct |
9 |
Correct |
5 ms |
3796 KB |
Output is correct |
10 |
Correct |
6 ms |
3796 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
23 ms |
3796 KB |
Output is correct |
13 |
Correct |
23 ms |
3820 KB |
Output is correct |
14 |
Correct |
22 ms |
3796 KB |
Output is correct |
15 |
Correct |
26 ms |
3820 KB |
Output is correct |
16 |
Correct |
37 ms |
3796 KB |
Output is correct |
17 |
Correct |
21 ms |
3824 KB |
Output is correct |
18 |
Correct |
28 ms |
3796 KB |
Output is correct |
19 |
Correct |
27 ms |
3824 KB |
Output is correct |
20 |
Correct |
21 ms |
3816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
1 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 |
1 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 |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
1 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 |
1 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 |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 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 |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
0 ms |
340 KB |
Output is correct |
38 |
Correct |
0 ms |
340 KB |
Output is correct |
39 |
Correct |
0 ms |
340 KB |
Output is correct |
40 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
1 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 |
1 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 |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 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 |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
0 ms |
340 KB |
Output is correct |
38 |
Correct |
0 ms |
340 KB |
Output is correct |
39 |
Correct |
0 ms |
340 KB |
Output is correct |
40 |
Correct |
0 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
724 KB |
Output is correct |
42 |
Correct |
1 ms |
724 KB |
Output is correct |
43 |
Correct |
2 ms |
724 KB |
Output is correct |
44 |
Correct |
1 ms |
724 KB |
Output is correct |
45 |
Correct |
1 ms |
724 KB |
Output is correct |
46 |
Correct |
1 ms |
724 KB |
Output is correct |
47 |
Correct |
1 ms |
724 KB |
Output is correct |
48 |
Correct |
1 ms |
724 KB |
Output is correct |
49 |
Correct |
2 ms |
724 KB |
Output is correct |
50 |
Correct |
1 ms |
724 KB |
Output is correct |
51 |
Correct |
1 ms |
724 KB |
Output is correct |
52 |
Correct |
1 ms |
724 KB |
Output is correct |
53 |
Correct |
1 ms |
724 KB |
Output is correct |
54 |
Correct |
1 ms |
724 KB |
Output is correct |
55 |
Correct |
2 ms |
724 KB |
Output is correct |
56 |
Correct |
2 ms |
724 KB |
Output is correct |
57 |
Correct |
1 ms |
724 KB |
Output is correct |
58 |
Correct |
1 ms |
724 KB |
Output is correct |
59 |
Correct |
1 ms |
724 KB |
Output is correct |
60 |
Correct |
1 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
3796 KB |
Output is correct |
2 |
Correct |
30 ms |
3796 KB |
Output is correct |
3 |
Correct |
27 ms |
3796 KB |
Output is correct |
4 |
Correct |
29 ms |
3812 KB |
Output is correct |
5 |
Correct |
28 ms |
3796 KB |
Output is correct |
6 |
Correct |
35 ms |
3796 KB |
Output is correct |
7 |
Correct |
29 ms |
3796 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 |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
6 ms |
3824 KB |
Output is correct |
6 |
Correct |
6 ms |
3796 KB |
Output is correct |
7 |
Correct |
6 ms |
3824 KB |
Output is correct |
8 |
Correct |
6 ms |
3820 KB |
Output is correct |
9 |
Correct |
5 ms |
3796 KB |
Output is correct |
10 |
Correct |
6 ms |
3796 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
23 ms |
3796 KB |
Output is correct |
13 |
Correct |
23 ms |
3820 KB |
Output is correct |
14 |
Correct |
22 ms |
3796 KB |
Output is correct |
15 |
Correct |
26 ms |
3820 KB |
Output is correct |
16 |
Correct |
37 ms |
3796 KB |
Output is correct |
17 |
Correct |
21 ms |
3824 KB |
Output is correct |
18 |
Correct |
28 ms |
3796 KB |
Output is correct |
19 |
Correct |
27 ms |
3824 KB |
Output is correct |
20 |
Correct |
21 ms |
3816 KB |
Output is correct |
21 |
Correct |
0 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 |
1 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 |
1 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 |
0 ms |
340 KB |
Output is correct |
36 |
Correct |
0 ms |
340 KB |
Output is correct |
37 |
Correct |
0 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
0 ms |
340 KB |
Output is correct |
40 |
Correct |
0 ms |
340 KB |
Output is correct |
41 |
Correct |
0 ms |
340 KB |
Output is correct |
42 |
Correct |
0 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
0 ms |
340 KB |
Output is correct |
47 |
Correct |
0 ms |
340 KB |
Output is correct |
48 |
Correct |
0 ms |
340 KB |
Output is correct |
49 |
Correct |
1 ms |
340 KB |
Output is correct |
50 |
Correct |
1 ms |
340 KB |
Output is correct |
51 |
Correct |
0 ms |
340 KB |
Output is correct |
52 |
Correct |
1 ms |
340 KB |
Output is correct |
53 |
Correct |
0 ms |
340 KB |
Output is correct |
54 |
Correct |
0 ms |
340 KB |
Output is correct |
55 |
Correct |
0 ms |
340 KB |
Output is correct |
56 |
Correct |
1 ms |
340 KB |
Output is correct |
57 |
Correct |
0 ms |
340 KB |
Output is correct |
58 |
Correct |
0 ms |
340 KB |
Output is correct |
59 |
Correct |
0 ms |
340 KB |
Output is correct |
60 |
Correct |
0 ms |
340 KB |
Output is correct |
61 |
Correct |
1 ms |
724 KB |
Output is correct |
62 |
Correct |
1 ms |
724 KB |
Output is correct |
63 |
Correct |
2 ms |
724 KB |
Output is correct |
64 |
Correct |
1 ms |
724 KB |
Output is correct |
65 |
Correct |
1 ms |
724 KB |
Output is correct |
66 |
Correct |
1 ms |
724 KB |
Output is correct |
67 |
Correct |
1 ms |
724 KB |
Output is correct |
68 |
Correct |
1 ms |
724 KB |
Output is correct |
69 |
Correct |
2 ms |
724 KB |
Output is correct |
70 |
Correct |
1 ms |
724 KB |
Output is correct |
71 |
Correct |
1 ms |
724 KB |
Output is correct |
72 |
Correct |
1 ms |
724 KB |
Output is correct |
73 |
Correct |
1 ms |
724 KB |
Output is correct |
74 |
Correct |
1 ms |
724 KB |
Output is correct |
75 |
Correct |
2 ms |
724 KB |
Output is correct |
76 |
Correct |
2 ms |
724 KB |
Output is correct |
77 |
Correct |
1 ms |
724 KB |
Output is correct |
78 |
Correct |
1 ms |
724 KB |
Output is correct |
79 |
Correct |
1 ms |
724 KB |
Output is correct |
80 |
Correct |
1 ms |
724 KB |
Output is correct |
81 |
Correct |
29 ms |
3796 KB |
Output is correct |
82 |
Correct |
30 ms |
3796 KB |
Output is correct |
83 |
Correct |
27 ms |
3796 KB |
Output is correct |
84 |
Correct |
29 ms |
3812 KB |
Output is correct |
85 |
Correct |
28 ms |
3796 KB |
Output is correct |
86 |
Correct |
35 ms |
3796 KB |
Output is correct |
87 |
Correct |
29 ms |
3796 KB |
Output is correct |
88 |
Correct |
18 ms |
3796 KB |
Output is correct |
89 |
Correct |
20 ms |
3824 KB |
Output is correct |
90 |
Correct |
23 ms |
3828 KB |
Output is correct |
91 |
Correct |
23 ms |
3824 KB |
Output is correct |
92 |
Correct |
27 ms |
3828 KB |
Output is correct |
93 |
Correct |
29 ms |
3844 KB |
Output is correct |
94 |
Correct |
28 ms |
3828 KB |
Output is correct |
95 |
Correct |
27 ms |
3796 KB |
Output is correct |
96 |
Correct |
32 ms |
3804 KB |
Output is correct |
97 |
Correct |
29 ms |
3816 KB |
Output is correct |
98 |
Correct |
24 ms |
3796 KB |
Output is correct |
99 |
Correct |
24 ms |
3820 KB |
Output is correct |
100 |
Correct |
24 ms |
3796 KB |
Output is correct |
101 |
Correct |
25 ms |
3820 KB |
Output is correct |
102 |
Correct |
25 ms |
3796 KB |
Output is correct |
103 |
Correct |
25 ms |
3820 KB |
Output is correct |
104 |
Correct |
28 ms |
3796 KB |
Output is correct |
105 |
Correct |
28 ms |
3796 KB |
Output is correct |