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;
typedef long long ll;
const int MX = 505;
int N, K;
int a[MX], b[MX];
vector<pair<int, int>> v;
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin >> N >> K;
int tot = 0;
for(int i = 1; i <= N; i++) {
cin >> a[i] >> b[i];
if(b[i] == -1) b[i] = 2e9;
else tot++;
v.push_back({b[i], a[i]});
}
sort(v.begin(), v.end(), [&](auto x, auto y) {
return x.first - x.second < y.first - y.second;
});
double ans = 1e9;
for(int x = 0; x <= min(K, tot); x++) {
int cnt = 1;
double res = 0;
vector<int> t;
for(int i = 0; i < x; i++) t.push_back(v[i].first);
sort(t.begin(), t.end());
for(int i = 0; i < x; i++) {
res += (double) t[i] / cnt;
cnt++;
}
t.clear();
for(int i = x; i < N; i++) t.push_back(v[i].second);
sort(t.begin(), t.end());
for(int i = 0; i < K - cnt + 1; i++) {
res += (double) t[i] / cnt;
}
ans = min(ans, res);
}
cout << fixed << setprecision(10) << ans << '\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... |