#ifdef Home
#define _GLIBCXX_DEBUG
#endif // Home
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int use[555], T, n, k;
vector < pair < int, int > > AB, A, B;
ld recur(int pos, int x, int y) {
if(x == y) {
ld tmp = .0;
for(int i = 0, j = k - x; i < n && j; ++ i) {
if(!use[i]) {
-- j;
tmp += (ld)A[i].first / (ld)(x + 1);
}
}
// cout << pos << ' ' << x << ' ' << y << ' ' << tmp << '\n';
return tmp;
}
ld tmp = 1e6;
++ y;
for(int i = pos; i < (int)B.size() - x + y; ++ i) {
use[B[i].second] = true;
tmp = min(tmp, (ld)B[i].first / (ld)y + recur(i + 1, x, y));
use[B[i].second] = false;
}
//cout << pos << ' ' << x << ' ' << y << ' ' << tmp << '\n';
return tmp;
}
main() {
#ifdef Home
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // Home
ios_base::sync_with_stdio(0);
cin.tie(0);
bool ok = true;
cin >> n >> k;
AB.resize(n);
A.resize(n);
for(int i = 0; i < n; ++ i) {
cin >> AB[i].first >> AB[i].second;
A[i] = {AB[i].first, i};
ok &= AB[i].second == -1 || AB[i].second == AB[i].first;
}
sort(A.begin(), A.end());
for(int i = 0; i < n; ++ i) {
if(AB[A[i].second].second != -1) {
B.push_back({AB[A[i].second].second, i});
}
}
sort(B.begin(), B.end());
ld ans = 1e6, tmp, c;
for(int t = 0; t <= (int)B.size(); ++ t) {
if(t == k) {
break;
}
if(!ok) {
ans = min(ans, recur(0, t, 0));
continue;
}
++ T;
tmp = .0, c = 1;
for(int i = 0; i < t; ++ i) {
tmp += (ld)B[i].first / c;
++ c;
use[B[i].second] = T;
}
for(int i = 0, j = k - t; i < n && j; ++ i) {
if(use[i] != T) {
-- j;
tmp += (ld)A[i].first / c;
}
}
ans = min(ans, tmp);
}
cout << fixed << setprecision(15) << ans;
}
Compilation message
Main.cpp:38:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
38 | main() {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 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 |
6 ms |
212 KB |
Output is correct |
18 |
Correct |
2 ms |
212 KB |
Output is correct |
19 |
Correct |
28 ms |
296 KB |
Output is correct |
20 |
Correct |
3 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
320 KB |
Output is correct |
22 |
Correct |
43 ms |
212 KB |
Output is correct |
23 |
Correct |
4 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
94 ms |
212 KB |
Output is correct |
26 |
Correct |
25 ms |
316 KB |
Output is correct |
27 |
Correct |
28 ms |
316 KB |
Output is correct |
28 |
Correct |
45 ms |
256 KB |
Output is correct |
29 |
Correct |
28 ms |
212 KB |
Output is correct |
30 |
Correct |
36 ms |
212 KB |
Output is correct |
31 |
Correct |
30 ms |
212 KB |
Output is correct |
32 |
Correct |
37 ms |
212 KB |
Output is correct |
33 |
Correct |
28 ms |
212 KB |
Output is correct |
34 |
Correct |
35 ms |
320 KB |
Output is correct |
35 |
Correct |
35 ms |
296 KB |
Output is correct |
36 |
Correct |
29 ms |
316 KB |
Output is correct |
37 |
Correct |
40 ms |
308 KB |
Output is correct |
38 |
Correct |
28 ms |
212 KB |
Output is correct |
39 |
Correct |
33 ms |
212 KB |
Output is correct |
40 |
Correct |
28 ms |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 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 |
6 ms |
212 KB |
Output is correct |
18 |
Correct |
2 ms |
212 KB |
Output is correct |
19 |
Correct |
28 ms |
296 KB |
Output is correct |
20 |
Correct |
3 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
320 KB |
Output is correct |
22 |
Correct |
43 ms |
212 KB |
Output is correct |
23 |
Correct |
4 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
94 ms |
212 KB |
Output is correct |
26 |
Correct |
25 ms |
316 KB |
Output is correct |
27 |
Correct |
28 ms |
316 KB |
Output is correct |
28 |
Correct |
45 ms |
256 KB |
Output is correct |
29 |
Correct |
28 ms |
212 KB |
Output is correct |
30 |
Correct |
36 ms |
212 KB |
Output is correct |
31 |
Correct |
30 ms |
212 KB |
Output is correct |
32 |
Correct |
37 ms |
212 KB |
Output is correct |
33 |
Correct |
28 ms |
212 KB |
Output is correct |
34 |
Correct |
35 ms |
320 KB |
Output is correct |
35 |
Correct |
35 ms |
296 KB |
Output is correct |
36 |
Correct |
29 ms |
316 KB |
Output is correct |
37 |
Correct |
40 ms |
308 KB |
Output is correct |
38 |
Correct |
28 ms |
212 KB |
Output is correct |
39 |
Correct |
33 ms |
212 KB |
Output is correct |
40 |
Correct |
28 ms |
324 KB |
Output is correct |
41 |
Execution timed out |
2569 ms |
212 KB |
Time limit exceeded |
42 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2571 ms |
340 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 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 |
1 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 |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 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 |
6 ms |
212 KB |
Output is correct |
38 |
Correct |
2 ms |
212 KB |
Output is correct |
39 |
Correct |
28 ms |
296 KB |
Output is correct |
40 |
Correct |
3 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
320 KB |
Output is correct |
42 |
Correct |
43 ms |
212 KB |
Output is correct |
43 |
Correct |
4 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
94 ms |
212 KB |
Output is correct |
46 |
Correct |
25 ms |
316 KB |
Output is correct |
47 |
Correct |
28 ms |
316 KB |
Output is correct |
48 |
Correct |
45 ms |
256 KB |
Output is correct |
49 |
Correct |
28 ms |
212 KB |
Output is correct |
50 |
Correct |
36 ms |
212 KB |
Output is correct |
51 |
Correct |
30 ms |
212 KB |
Output is correct |
52 |
Correct |
37 ms |
212 KB |
Output is correct |
53 |
Correct |
28 ms |
212 KB |
Output is correct |
54 |
Correct |
35 ms |
320 KB |
Output is correct |
55 |
Correct |
35 ms |
296 KB |
Output is correct |
56 |
Correct |
29 ms |
316 KB |
Output is correct |
57 |
Correct |
40 ms |
308 KB |
Output is correct |
58 |
Correct |
28 ms |
212 KB |
Output is correct |
59 |
Correct |
33 ms |
212 KB |
Output is correct |
60 |
Correct |
28 ms |
324 KB |
Output is correct |
61 |
Execution timed out |
2569 ms |
212 KB |
Time limit exceeded |
62 |
Halted |
0 ms |
0 KB |
- |