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>
#define mp(x...) array<int, 2>({x})
using namespace std;
constexpr static int INF = 1e6;
constexpr static int MXSIZE = 500;
bitset<MXSIZE> added;
array<int, 2> a[MXSIZE], b[MXSIZE];
int n, k;
double calculate(int cc)
{
int count = 0;
double cost = 0;
for (int i = 0; i < cc; i++)
{
added[b[i][1]] = true;
cost += static_cast<double>(b[i][0]) / (i+1);
count++;
}
for (int i = 0; i < n && count < k; i++)
{
if (added[a[i][1]])
continue;
cost += static_cast<double>(a[i][0]) / (cc+1);
count++;
}
for (int i = 0; i < cc; i++)
added[b[i][1]] = false;
return cost;
}
int main()
{
cin >> n;
cin >> k;
for (int i = 0; i < n; i++)
{
int aa, bb;
cin >> aa >> bb;
a[i] = mp(aa, i);
bb = bb == -1 ? INF : bb;
b[i] = mp(bb, i);
}
sort(a, a + n);
sort(b, b + n);
double best = INF;
for (int i = 0; i <= k && (i == 0 || b[i-1][0] != INF); i++)
best = min(best, calculate(i));
cout << fixed;
cout << setprecision(4);
cout << best << "\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... |