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;
using ll = long long;
using ld = long double;
const ld INF = 1e18;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n, k;
cin >> n >> k;
pair<ld, ld> c[n + 1];
for(int i = 1; i <= n; i++) {
cin >> c[i].first >> c[i].second;
if(c[i].second == -1) c[i].second = INF;
}
sort(c + 1, c + n + 1, [](pair<ld, ld> x, pair<ld, ld> y){return x.second < y.second;});
ld res = INF;
for(int t = 0; t <= k; t++) {
vector<ld> dp(k - t + 1, INF);
dp[0] = 0;
for(int i = 1; i <= n; i++) {
vector<ld> newdp(k - t + 1, INF);
for(int j = 0; j <= k - t; j++) {
if(j) newdp[j] = min(newdp[j], dp[j - 1] + c[i].first / (t + 1));
if(i - j <= t) newdp[j] = min(newdp[j], dp[j] + c[i].second / (i - j));
else newdp[j] = min(newdp[j], dp[j]);
}
dp = newdp;
}
res = min(res, dp[k - t]);
}
cout << setprecision(9) << fixed << res;
}
# | 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... |