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 f first
#define s second
#define int long long
const int N = 550;
const int inf = 1e18;
int n, k;
pair<int, int> a[N];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
cin >> n >> k;
vector<int> tm;
for (int i = 0;i < n;i++) {
cin >> a[i].f >> a[i].s;
tm.push_back(a[i].f);
if (a[i].s == -1)
a[i].s = inf;
}
double ans = 0;
sort(tm.begin(), tm.end());
for (int i = 0;i < k;i++)
ans += tm[i];
for (int mask = 1;mask < (1 << n);mask++) {
vector<int> gas;
for (int i = 0;i < n;i++) {
if (mask & (1 << i)) {
gas.push_back(a[i].s);
}
}
sort(gas.begin(), gas.end());
int m = gas.size();
if (m > k)
continue;
double s = 0;
int i = 1;
for (auto u : gas)
s += (double)u / (i++);
vector<int> o;
for (int i = 0;i < n;i++) {
if (!(mask & (1 << i)))
o.push_back(a[i].f);
}
sort(o.begin(), o.end());
for (int i = 0;i < k - m;i++)
s += (double)o[i] / (m + 1);
ans = min(ans, s);
}
cout << fixed << setprecision(15) << ans;
}
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... |