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 pii pair<int, int>
#define INF 5000000
using namespace std;
bool cmp(pii a, pii b) {
if (a.second == -1 || b.second == -1) return a.second != -1;
return a.second < b.second;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, K;
cin >> n >> K;
vector<pii>v(n+1);
vector<double>a(n+1), b(n+1);
for (int i = 1 ; i <= n ;i++) cin >> v[i].first >> v[i].second;
//sort(v.begin()+1, v.end(), cmp);
for (int i = 1 ; i <= n ;i++) a[i] = (double)v[i].first, b[i] = (double)v[i].second;
vector<vector<vector<double> > >dp(505, vector<vector<double> >(505, vector<double>(505, INF)) );
//double dp[505][505][505];
dp[0][0][1] = 0.0;
double ans = INF;
for (int i = 1 ; i <= n ; i++) {//first i people
//cout << i << ": \n";
for (int j = 0 ; j <= i ; j++) {// have how many people
//cout << j << ": ";
for (int k = 1 ; k <= j+1 ; k++) {// get how many people
dp[i][j][k] = dp[i-1][j][k];
if (j > 0) dp[i][j][k] = min(dp[i][j][k], dp[i-1][j-1][k] + (a[i] / k));
if (k > 1 && b[i] != -1) dp[i][j][k] = min(dp[i][j][k], dp[i-1][j-1][k-1] + b[i] / (k-1));
//cout << dp[i][j][k] <<" ";
if (j >= K) ans = min(ans, dp[i][j][k]);
}
//cout << "\n";
}
}
cout << fixed << setprecision(6) << ans << "\n";
//for (auto &i : v) cout << i.first <<" " << i.second << "\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... |