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<pair<int, int>> v;
int main() {
int n, k; cin >> n >> k;
for (int i = 0; i < n; i++) {
int a, b; cin >> a >> b;
if (b == -1) b = 1e9;
v.emplace_back(a, b);
}
sort(v.begin(), v.end(), [](pair<int, int> a, pair<int, int> b) {
if (a.second == b.second) {
return a.first < b.first;
}
return a.second < b.second;
});
double ans = 2e9;
for (int i = 0; i <= k; i++) {
// take b up to here
double total = 0;
for (int j = 0; j < i; j++) {
total += (double) (v[j].second) / (double) (j + 1);
}
vector<pair<int, int>> cur;
for (int j = i; j < n; j++) {
cur.push_back(v[j]);
}
sort(cur.begin(), cur.end());
for (int j = 0; j < k - i; j++) {
total += (double) (cur[j].first) / (double) (i + 1);
}
ans = min(ans, total);
}
cout << 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... |