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;
vector<tuple<long double, long double, int>> all;
vector<tuple<long double, long double, int>> collaborators;
int n, k;
bool cmp(const tuple<long double, long double, int> a, const tuple<long double, long double, int> b){
if(std::get<1>(a) != std::get<1>(b))
return std::get<1>(a) < std::get<1>(b);
return std::get<0>(a) < std::get<0>(b);
}
long double solve(int z){
vector<bool>activ (n+1, 0);
int it = 0;
long double tajm = 0;
long double dzielnik = 1;
for(int i = 0; i < z; i++){
auto [a, b, id] = collaborators[i];
tajm += b/dzielnik;
dzielnik += 1;
activ[id] = 1;
it++;
}
for(int i = 0; i < n && it < k; i++){
auto [a, b, id] = all[i];
if(activ[id]) continue;
tajm += a/dzielnik;
it++;
}
return tajm;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for(int i = 1; i <= n; i++){
long double a, b;
cin >> a >> b;
all.push_back({a, b, i});
if(b >= a)
collaborators.push_back({a, b, i});
}
sort(all.begin(), all.end());
sort(collaborators.begin(), collaborators.end(), cmp);
long double res = 1e9;
res = min(res, solve(0));
for(int i = 0; i < min((int)collaborators.size(), k); i++)
res = min(res, solve(i));
cout << fixed << setprecision(10) << res << "\n";
}
# | 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... |