#include<bits/stdc++.h>
using namespace std;
int n;int K;
int M;
int ar[200005];
int br[200005];
double ans;
bool cmp(pair<int,int>i,pair<int,int>j){
if(i.second<j.second){return 1;}
if(i.second>j.second){return 0;}
if(i.first<j.first){return 1;}
return 0;
}
double solve(int m){
vector<pair<int,int>>tar;
for(int i=1;i<=n;i++){
tar.push_back({ar[i],br[i]});
}
sort(tar.begin(),tar.end(),cmp);
vector<pair<int,int>>anv;
for(int i=0;i<m;i++){
anv.push_back(tar[i]);
}
vector<int>tv;
for(int i=m;i<n;i++){
tv.push_back(tar[i].first);
}
sort(tv.begin(),tv.end());
/*
for(int i=0;i<tar.size();i++){
cout<<tar[i].first<<"_"<<tar[i].second<<endl;
}*/
double ret=0;
for(int i=0;i<K-m;i++){
ret+=(double)tv[i]/(double)(m+1);
}
for(int i=0;i<anv.size();i++){
ret+=(double)anv[i].second/(double)(i+1);
}
//cout<<fixed<<setprecision(6)<<ret<<endl;
return ret;
}
signed main(){
cin>>n>>K;
M=0;
for(int i=1;i<=n;i++){
cin>>ar[i]>>br[i];
if(br[i]!=-1){
M++;
}else{
br[i]=2000;
}
}
ans=500000;
for(int i=0;i<=min(K,M);i++){
ans=min(ans,solve(i));
// cout<<endl<<endl;
}
cout<<fixed<<setprecision(6)<<ans<<endl;
/*
double l=0;double r=500000;
for(int ttt=0;ttt<90;ttt++){
double mi=(l+r)/2;
if(ok(mi)){
l=mi;
}else{
r=mi;
}
}
cout<<fixed<<setprecision(6)<<l<<endl;
*/
}
Compilation message
Main.cpp: In function 'double solve(int)':
Main.cpp:44:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int i=0;i<anv.size();i++){
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
264 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
248 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 |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
264 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
248 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 |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
336 KB |
Output is correct |
13 |
Correct |
10 ms |
328 KB |
Output is correct |
14 |
Correct |
6 ms |
324 KB |
Output is correct |
15 |
Correct |
17 ms |
328 KB |
Output is correct |
16 |
Correct |
15 ms |
328 KB |
Output is correct |
17 |
Correct |
6 ms |
212 KB |
Output is correct |
18 |
Correct |
24 ms |
212 KB |
Output is correct |
19 |
Correct |
20 ms |
212 KB |
Output is correct |
20 |
Correct |
6 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
312 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 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 |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
312 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 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 |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
312 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 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 |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
25 ms |
324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
264 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
248 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 |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
336 KB |
Output is correct |
13 |
Correct |
10 ms |
328 KB |
Output is correct |
14 |
Correct |
6 ms |
324 KB |
Output is correct |
15 |
Correct |
17 ms |
328 KB |
Output is correct |
16 |
Correct |
15 ms |
328 KB |
Output is correct |
17 |
Correct |
6 ms |
212 KB |
Output is correct |
18 |
Correct |
24 ms |
212 KB |
Output is correct |
19 |
Correct |
20 ms |
212 KB |
Output is correct |
20 |
Correct |
6 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
312 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
312 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
312 KB |
Output is correct |
28 |
Correct |
1 ms |
308 KB |
Output is correct |
29 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |