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;
for(int i = 0; i < N; i++) {
cin >> a[i] >> b[i];
}
double ans = 1e9;
for(int i = 0; i < (1 << N); i++) {
bool can = 1;
for(int j = 0; j < N; j++) {
if((i >> j & 1) && b[j] == -1) can = 0;
}
if(!can) continue;
double res = 0;
int cnt = 1;
vector<int> v;
for(int j = 0; j < N; j++) {
if(i >> j & 1) v.push_back(b[j]);
}
sort(v.begin(), v.end());
for(auto x : v) {
res += (double) x / cnt;
cnt++;
}
if(cnt > K) continue;
v.clear();
for(int j = 0; j < N; j++) {
if(!(i >> j & 1)) v.push_back(a[j]);
}
sort(v.begin(), v.end());
for(int i = 0; i < K - cnt + 1; i++) {
res += (double) v[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... |