#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 10;
const int mxn = 20;
int a[mxn], n;
int b[mxn], k;
vector<int> good;
vector<int> badd;
double ans = 1e9;
void solve2(int map) {
vector<int> vote = badd;
vector<int> help;
double ret = 0.0;
for(int i = 0; i < (int)good.size(); i++)
if(map & (1 << i))
help.push_back(good[i]);
else
vote.push_back(good[i]);
if((int)help.size() > k) return;
sort(help.begin(), help.end(), [&](int i, int j) { return b[i] < b[j]; });
sort(vote.begin(), vote.end(), [&](int i, int j) { return a[i] < a[j]; });
int helpers = 0;
for(int i : help) {
ret += 1.0 * b[i] / (1.0 + helpers);
helpers++;
}
for(int j = 0; j < (k - (int)help.size()); j++) {
int i = vote[j];
ret += 1.0 * a[i] / (1.0 + helpers);
}
ans = min(ans, ret);
}
void sub2() {
for(int bit = 0; bit < (1 << (int)good.size()); bit++)
solve2(bit);
cout << setprecision(5) << fixed << ans << '\n';
exit(0);
}
void solve1(int t) {
if(k - t >= (int)badd.size()) return;
double ret = 0.0;
int helpers = 0;
for(int j = 0; j < t; j++) {
int i = good[j];
ret += 1.0 * a[i] / (1.0 + helpers);
helpers++;
}
assert(helpers == t);
for(int j = 0; j < (k - t); j++) {
if(j >= (int)badd.size()) for(;;);
int i = badd[j];
ret += 1.0 * a[i] / (1.0 + t);
}
ans = min(ans, ret);
}
void sub1() {
sort(good.begin(), good.end(), [&](int i, int j) { return a[i] < a[j]; });
sort(badd.begin(), badd.end(), [&](int i, int j) { return a[i] < a[j]; });
for(int i = 0; i <= (int)good.size() && i < k; i++)
solve1(i);
cout << setprecision(5) << fixed << ans << '\n';
exit(0);
}
int main() {
bool gay = 0;
cin >> n >> k;
for(int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
if(b[i] == -1) {
b[i] = inf;
badd.push_back(i);
}
else {
if(a[i] != b[i])
gay = 1;
good.push_back(i);
}
}
if(n <= 20 && gay) sub2();
if(!gay) sub1();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
432 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
432 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
297 ms |
596 KB |
Output is correct |
17 |
Correct |
362 ms |
344 KB |
Output is correct |
18 |
Correct |
43 ms |
344 KB |
Output is correct |
19 |
Correct |
467 ms |
404 KB |
Output is correct |
20 |
Correct |
26 ms |
424 KB |
Output is correct |
21 |
Correct |
6 ms |
348 KB |
Output is correct |
22 |
Correct |
458 ms |
404 KB |
Output is correct |
23 |
Correct |
25 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
487 ms |
348 KB |
Output is correct |
26 |
Correct |
118 ms |
348 KB |
Output is correct |
27 |
Correct |
456 ms |
344 KB |
Output is correct |
28 |
Correct |
455 ms |
596 KB |
Output is correct |
29 |
Correct |
456 ms |
348 KB |
Output is correct |
30 |
Correct |
457 ms |
404 KB |
Output is correct |
31 |
Correct |
457 ms |
348 KB |
Output is correct |
32 |
Correct |
460 ms |
344 KB |
Output is correct |
33 |
Correct |
463 ms |
404 KB |
Output is correct |
34 |
Correct |
449 ms |
404 KB |
Output is correct |
35 |
Correct |
452 ms |
408 KB |
Output is correct |
36 |
Correct |
462 ms |
404 KB |
Output is correct |
37 |
Correct |
461 ms |
348 KB |
Output is correct |
38 |
Correct |
455 ms |
420 KB |
Output is correct |
39 |
Correct |
473 ms |
408 KB |
Output is correct |
40 |
Correct |
459 ms |
592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
432 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
297 ms |
596 KB |
Output is correct |
17 |
Correct |
362 ms |
344 KB |
Output is correct |
18 |
Correct |
43 ms |
344 KB |
Output is correct |
19 |
Correct |
467 ms |
404 KB |
Output is correct |
20 |
Correct |
26 ms |
424 KB |
Output is correct |
21 |
Correct |
6 ms |
348 KB |
Output is correct |
22 |
Correct |
458 ms |
404 KB |
Output is correct |
23 |
Correct |
25 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
487 ms |
348 KB |
Output is correct |
26 |
Correct |
118 ms |
348 KB |
Output is correct |
27 |
Correct |
456 ms |
344 KB |
Output is correct |
28 |
Correct |
455 ms |
596 KB |
Output is correct |
29 |
Correct |
456 ms |
348 KB |
Output is correct |
30 |
Correct |
457 ms |
404 KB |
Output is correct |
31 |
Correct |
457 ms |
348 KB |
Output is correct |
32 |
Correct |
460 ms |
344 KB |
Output is correct |
33 |
Correct |
463 ms |
404 KB |
Output is correct |
34 |
Correct |
449 ms |
404 KB |
Output is correct |
35 |
Correct |
452 ms |
408 KB |
Output is correct |
36 |
Correct |
462 ms |
404 KB |
Output is correct |
37 |
Correct |
461 ms |
348 KB |
Output is correct |
38 |
Correct |
455 ms |
420 KB |
Output is correct |
39 |
Correct |
473 ms |
408 KB |
Output is correct |
40 |
Correct |
459 ms |
592 KB |
Output is correct |
41 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
42 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |