This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define fs first
#define sc second
#define ld double
const ll inf = 1e12;
const ll mxn = 550;
pll arr[mxn];
ll N,K;
bitset<mxn> done;
inline ld f(ll cnt){
done.reset();
vector<pll> v;
for(int i= 0;i<N;i++)v.push_back({arr[i].sc,i});
sort(v.begin(),v.end());
ld re = 0,c = 1;
for(int i = 0;i<cnt;i++){
re += v[i].fs/c;
c+=1;
done[v[i].sc] = true;
}
ll now = cnt;
for(int i = 0;i<N;i++){
if(now>=K)break;
if(done[i])continue;
re += arr[i].fs/c;
now++;
}
return re;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>N>>K;
for(int i = 0;i<N;i++)cin>>arr[i].fs>>arr[i].sc,arr[i].sc = (arr[i].sc == -1?inf:arr[i].sc);
sort(arr,arr+N);
ld ans = inf;
for(int i = 0;i<=K;i++)ans = min(ans,f(i));
cout<<fixed<<setprecision(20)<<ans;
}
# | 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... |