#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define pii pair<int, int>
#define ff first
#define ss second
#define ld long double
#define pb push_back
pair<ld, ld> a[300100];
ll b[300100];
ll n, m;
ll us[200100];
bool cmp(int x, int y){
return a[x].ss < a[y].ss;
}
void solve(){
cin>>n>>m;
int cnt = 0;
vector<int> q;
for(int i=1; i<=n; i++){
cin>>a[i].ff>>a[i].ss;
if(a[i].ss == -1) a[i].ss = 1e9;
else cnt ++, q.pb(i);
}
sort(a + 1, a + 1 + n);
ld ans = 1e18;
for(int k=0; k<(1 << n); k++){
ld res = 0;
vector<int> q;
for(int i=0; i<n; i++){
us[i + 1] = 0;
if((k & (1 << i))){
q.pb(i + 1);
if(a[i + 1].ss == 1e9) res = -1;
}
}
if(res == -1) continue;
sort(q.begin(), q.end(), cmp);
for(int i=0; i<q.size(); i++){
us[q[i]] = 1;
res += a[q[i]].ss / (i + 1);
}
int cnt = q.size();
for(int i=1; i<=n; i++){
if(cnt >= m) break;
if(us[i]) continue;
us[i] = 1;
res += a[i].ff / (q.size() + 1);
cnt ++;
}
ans = min(ans, res);
}
cout<<fixed<<setprecision(9)<<ans<<'\n';
}
signed main(){
solve();
}
Compilation message
Main.cpp: In function 'void solve()':
Main.cpp:44:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int i=0; i<q.size(); i++){
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
0 ms |
4444 KB |
Output is correct |
5 |
Correct |
1571 ms |
4540 KB |
Output is correct |
6 |
Correct |
1587 ms |
4556 KB |
Output is correct |
7 |
Correct |
1541 ms |
4692 KB |
Output is correct |
8 |
Correct |
1554 ms |
4540 KB |
Output is correct |
9 |
Correct |
1559 ms |
4544 KB |
Output is correct |
10 |
Correct |
1538 ms |
4540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
0 ms |
4444 KB |
Output is correct |
5 |
Correct |
1571 ms |
4540 KB |
Output is correct |
6 |
Correct |
1587 ms |
4556 KB |
Output is correct |
7 |
Correct |
1541 ms |
4692 KB |
Output is correct |
8 |
Correct |
1554 ms |
4540 KB |
Output is correct |
9 |
Correct |
1559 ms |
4544 KB |
Output is correct |
10 |
Correct |
1538 ms |
4540 KB |
Output is correct |
11 |
Correct |
1 ms |
4440 KB |
Output is correct |
12 |
Execution timed out |
2526 ms |
4544 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4540 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4540 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
484 ms |
4444 KB |
Output is correct |
17 |
Correct |
494 ms |
4444 KB |
Output is correct |
18 |
Correct |
207 ms |
4444 KB |
Output is correct |
19 |
Correct |
508 ms |
4536 KB |
Output is correct |
20 |
Correct |
198 ms |
4444 KB |
Output is correct |
21 |
Correct |
184 ms |
4444 KB |
Output is correct |
22 |
Correct |
559 ms |
4444 KB |
Output is correct |
23 |
Correct |
192 ms |
4444 KB |
Output is correct |
24 |
Correct |
181 ms |
4444 KB |
Output is correct |
25 |
Correct |
556 ms |
4444 KB |
Output is correct |
26 |
Correct |
263 ms |
4532 KB |
Output is correct |
27 |
Correct |
542 ms |
4444 KB |
Output is correct |
28 |
Correct |
567 ms |
4532 KB |
Output is correct |
29 |
Correct |
511 ms |
4444 KB |
Output is correct |
30 |
Correct |
547 ms |
4444 KB |
Output is correct |
31 |
Correct |
541 ms |
4444 KB |
Output is correct |
32 |
Correct |
471 ms |
4444 KB |
Output is correct |
33 |
Correct |
542 ms |
4444 KB |
Output is correct |
34 |
Correct |
437 ms |
4444 KB |
Output is correct |
35 |
Correct |
478 ms |
4444 KB |
Output is correct |
36 |
Correct |
431 ms |
4536 KB |
Output is correct |
37 |
Correct |
406 ms |
4536 KB |
Output is correct |
38 |
Correct |
404 ms |
4444 KB |
Output is correct |
39 |
Correct |
402 ms |
4548 KB |
Output is correct |
40 |
Correct |
377 ms |
4532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4540 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
484 ms |
4444 KB |
Output is correct |
17 |
Correct |
494 ms |
4444 KB |
Output is correct |
18 |
Correct |
207 ms |
4444 KB |
Output is correct |
19 |
Correct |
508 ms |
4536 KB |
Output is correct |
20 |
Correct |
198 ms |
4444 KB |
Output is correct |
21 |
Correct |
184 ms |
4444 KB |
Output is correct |
22 |
Correct |
559 ms |
4444 KB |
Output is correct |
23 |
Correct |
192 ms |
4444 KB |
Output is correct |
24 |
Correct |
181 ms |
4444 KB |
Output is correct |
25 |
Correct |
556 ms |
4444 KB |
Output is correct |
26 |
Correct |
263 ms |
4532 KB |
Output is correct |
27 |
Correct |
542 ms |
4444 KB |
Output is correct |
28 |
Correct |
567 ms |
4532 KB |
Output is correct |
29 |
Correct |
511 ms |
4444 KB |
Output is correct |
30 |
Correct |
547 ms |
4444 KB |
Output is correct |
31 |
Correct |
541 ms |
4444 KB |
Output is correct |
32 |
Correct |
471 ms |
4444 KB |
Output is correct |
33 |
Correct |
542 ms |
4444 KB |
Output is correct |
34 |
Correct |
437 ms |
4444 KB |
Output is correct |
35 |
Correct |
478 ms |
4444 KB |
Output is correct |
36 |
Correct |
431 ms |
4536 KB |
Output is correct |
37 |
Correct |
406 ms |
4536 KB |
Output is correct |
38 |
Correct |
404 ms |
4444 KB |
Output is correct |
39 |
Correct |
402 ms |
4548 KB |
Output is correct |
40 |
Correct |
377 ms |
4532 KB |
Output is correct |
41 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
42 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2568 ms |
4544 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
0 ms |
4444 KB |
Output is correct |
5 |
Correct |
1571 ms |
4540 KB |
Output is correct |
6 |
Correct |
1587 ms |
4556 KB |
Output is correct |
7 |
Correct |
1541 ms |
4692 KB |
Output is correct |
8 |
Correct |
1554 ms |
4540 KB |
Output is correct |
9 |
Correct |
1559 ms |
4544 KB |
Output is correct |
10 |
Correct |
1538 ms |
4540 KB |
Output is correct |
11 |
Correct |
1 ms |
4440 KB |
Output is correct |
12 |
Execution timed out |
2526 ms |
4544 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |