#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);
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};
}
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;
}
// cout << t << " <<<<<<<<<<<<<<\n";
ans = min(ans, recur(0, t, 0));
// cout << "<<<<<<<<<<<<<<<<\n\n\n\n\n";
}
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() {
| ^~~~
Main.cpp: In function 'int main()':
Main.cpp:60:19: warning: unused variable 'tmp' [-Wunused-variable]
60 | ld ans = 1e6, tmp, c;
| ^~~
Main.cpp:60:24: warning: unused variable 'c' [-Wunused-variable]
60 | ld ans = 1e6, tmp, c;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 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 |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 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 |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 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 |
Execution timed out |
2560 ms |
340 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 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 |
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 |
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 |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 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 |
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 |
6 ms |
212 KB |
Output is correct |
18 |
Correct |
2 ms |
212 KB |
Output is correct |
19 |
Correct |
30 ms |
316 KB |
Output is correct |
20 |
Correct |
3 ms |
324 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
37 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 |
96 ms |
212 KB |
Output is correct |
26 |
Correct |
25 ms |
212 KB |
Output is correct |
27 |
Correct |
34 ms |
296 KB |
Output is correct |
28 |
Correct |
36 ms |
212 KB |
Output is correct |
29 |
Correct |
28 ms |
320 KB |
Output is correct |
30 |
Correct |
36 ms |
212 KB |
Output is correct |
31 |
Correct |
35 ms |
316 KB |
Output is correct |
32 |
Correct |
36 ms |
300 KB |
Output is correct |
33 |
Correct |
28 ms |
212 KB |
Output is correct |
34 |
Correct |
29 ms |
320 KB |
Output is correct |
35 |
Correct |
44 ms |
212 KB |
Output is correct |
36 |
Correct |
28 ms |
324 KB |
Output is correct |
37 |
Correct |
34 ms |
212 KB |
Output is correct |
38 |
Correct |
28 ms |
300 KB |
Output is correct |
39 |
Correct |
33 ms |
212 KB |
Output is correct |
40 |
Correct |
29 ms |
316 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 |
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 |
1 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 |
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 |
6 ms |
212 KB |
Output is correct |
18 |
Correct |
2 ms |
212 KB |
Output is correct |
19 |
Correct |
30 ms |
316 KB |
Output is correct |
20 |
Correct |
3 ms |
324 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
37 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 |
96 ms |
212 KB |
Output is correct |
26 |
Correct |
25 ms |
212 KB |
Output is correct |
27 |
Correct |
34 ms |
296 KB |
Output is correct |
28 |
Correct |
36 ms |
212 KB |
Output is correct |
29 |
Correct |
28 ms |
320 KB |
Output is correct |
30 |
Correct |
36 ms |
212 KB |
Output is correct |
31 |
Correct |
35 ms |
316 KB |
Output is correct |
32 |
Correct |
36 ms |
300 KB |
Output is correct |
33 |
Correct |
28 ms |
212 KB |
Output is correct |
34 |
Correct |
29 ms |
320 KB |
Output is correct |
35 |
Correct |
44 ms |
212 KB |
Output is correct |
36 |
Correct |
28 ms |
324 KB |
Output is correct |
37 |
Correct |
34 ms |
212 KB |
Output is correct |
38 |
Correct |
28 ms |
300 KB |
Output is correct |
39 |
Correct |
33 ms |
212 KB |
Output is correct |
40 |
Correct |
29 ms |
316 KB |
Output is correct |
41 |
Execution timed out |
2564 ms |
212 KB |
Time limit exceeded |
42 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2561 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 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 |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 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 |
Execution timed out |
2560 ms |
340 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |