#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fst first
#define snd second
#define pb push_back
#define forn(i,a,b) for(int i = a; i < b; i++)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define dbg(v) cout<<"Line("<<__LINE__<<"): "<<#v<<" = "<<v<<'\n';
#define pi pair<int,int>
#define pll pair<ll,ll>
typedef long long ll;
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_multiset;
int main(){
ll n,k; cin>>n>>k;
vector<ll> b(n);
vector<ll> a(n); forn(i,0,n) cin>>a[i]>>b[i];
vector<pair<pair<ll,ll>,ll>> sxb; // sorted x b
vector<pair<pair<ll,ll>,ll>> sxa(n); // sorted x a
forn(i,0,n) if(b[i]!=-1) sxb.pb({{b[i],a[i]},i}); sort(ALL(sxb));
forn(i,0,n) sxa[i]={{a[i],b[i]},i}; sort(ALL(sxa));
long double res = k*2000;
forn(i,0,SZ(sxb)+1){
vector<bool> vis(n,false);
ll conq = i;
long double time = 0;
forn(j,0,i){
time+=sxb[j].fst.fst;
vis[sxb[j].snd]=true;
}
//cout<<i<<" "<<time<<'\n';
forn(j,0,n){
if(vis[sxa[j].snd]) continue;
if(conq>=k) break;
conq++;
//cout<<sxa[j].fst.fst<<" / "<<(i+1)<<'\n';
time+=(long double)sxa[j].fst.fst/(long double)(i+1);
}
//cout<<i<<" "<<time<<'\n';
res=min(res,time);
}
cout<<fixed<<setprecision(10)<<res<<'\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |