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>
#define forn(i,n) for(int i = 0;i < (n);i++)
#define Forn(i,n) for(int i = 1;i <= (n);i++)
#define all(p) p.begin(),p.end()
#define pb push_back
#define F first
#define S second
#define rz resize
#define sz(x) x.size()
#define int long long
#define vi vector<int>
#define pii pair<int,int>
using namespace std;
const int INF = 5000009;
int n,k;
vector<pii> a;
bool cmp(pii x,pii y){
return (x.F < y.F || (x.F == y.F && x.S < y.S));
}
void solve(){
cin >> n >> k;
n++;
a.rz(n);
vi c(n);
forn(i,n){
if(i == n-1){
c[n-1] = INF;
a[n-1].S = INF,a[n-1].F = INF;
}
cin >> a[i].S >> a[i].F;
c[i] = a[i].S;
if(a[i].F == -1) a[i].F = INF;
}
sort(all(c));
sort(all(a),cmp);
double ans = 0;
forn(i,k) ans += c[i];
double res = 0;
for(int i = 1;i <= k;i++){
res += (double)a[i-1].F/(i);
vi b;
for(int j = i;j < n;j++){
b.pb(a[j].S);
}
sort(all(b));
double tr = 0;
for(int r = 0;r < k-i;r++){
tr += b[r];
}
//cout << res << ' ' << tr << ' ' << (double)tr/(i+1) << '\n';
ans = min(ans,(double) res + (double)tr / (i+1));
}
cout << ans << '\n';
}
signed main(){
cin.tie(NULL);
cout.tie(NULL);
ios_base::sync_with_stdio(0);
cout << fixed << setprecision(4);
solve();
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... |