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 int long long
#define db long double
int INF = 0x3f3f3f3f3f3f3f3f;
struct Val {
int a, b, idx;
Val(int x = 0, int y = 0, int z = 0) : a(x), b(y), idx(z) {}
};
bool comp1(const Val& a, const Val& b) {
return (make_pair(a.b, a.idx) < make_pair(b.b, b.idx));
}
bool comp2(const Val& a, const Val& b) {
return (make_pair(a.a, a.idx) < make_pair(b.a, b.idx));
}
int32_t main() {
int n, k;
cin >> n >> k;
vector<Val> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i].a >> v[i].b;
if (v[i].b == -1) v[i].b = INF;
v[i].idx = (i + 1);
}
sort(v.begin(), v.end(), comp1);
cout << fixed << setprecision(14);
db ans = INF;
for (int i = 0; i <= k; i++) {
//cout << i << "\n";
db mC = 0;
for (int j = 0; j < i; j++) {
mC += (((db)v[j].b)/((db)(j + 1)));
//cout << v[i].idx << " " << mC << " " << v[i].b << "\n";
}
//cout << "getting rest\n";
vector<Val> others;
for (int j = i; j < n; j++) {
others.push_back(v[j]);
}
sort(others.begin(), others.end(), comp2);
int rem = (k - i);
for (int j = 0; j < rem; j++) {
mC += (((db)others[j].a)/((db)(i + 1)));
//cout << others[j].idx << " " << mC << "\n";
}
ans = min(ans, mC);
}
cout << 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... |