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 int64_t
signed main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
int n, K; cin >> n >> K;
vector<array<int, 3>> inputA(n);
vector<array<int, 3>> inputB(n);
for (int i=0; i<n; i++) {
int a, b; cin >> a >> b;
if (b == -1) b = 1e18;
inputA[i]={a, b, i};
inputB[i]={b, a, i};
}
sort(inputA.begin(), inputA.end());
sort(inputB.begin(), inputB.end());
// vector<bool> topK(n, 0);
// for (int i = 0; i<K; i++) {
// topK[inputA[i][2]] = 1;
// }
double res = 1e10;
array<array<double, 505>, 505> dp;
for (int i=0; i<n; i++) {
for (auto &a: dp) for (auto &b: a) b = 1e10;
dp[0][0] = 0;
for (int j=0; j<n; j++) {
for (int k=0; k<=min(i, j); k++) {
cerr << dp[j][k] << " ";
if (dp[j][k] == 1e10) continue;
dp[j+1][k] = min(dp[j+1][k], dp[j][k]+(double)inputB[j][1]/(double)(i+1));
dp[j+1][k+1] = min(dp[j+1][k+1], dp[j][k]+(double)inputB[j][0]/(double)(k+1));
}
cerr << "\n";
}
cerr << "\n";
res = min(res, dp[n][i]);
}
// for (int colabs = 0; colabs<=K; colabs++) {
// for (int inTopK = 0; inTopK<=K; inTopK++) {
// double tmp = dp[n][inTopK][colabs];
// cerr << tmp << "\n";
// if (tmp == 1e10) continue;
// for (int i = 0; i<K+inTopK; i++) {
// tmp += inputA[i][0];
// }
// res = min(res, tmp);
// cerr << "-" << tmp << "\n";
// }
// }
cout.precision(100);
cout << res << "\n";
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... |