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;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=507;
const ld INF=1e9+7;
pair<int,int>T[LIM];
ld dp[LIM][LIM];
int n, k;
ld solve(int m) {
rep(i, n+1) rep(j, k+1) dp[i][j]=INF;
dp[0][0]=0;
for(int i=1; i<=n; ++i) {
for(int j=0; j<=i; ++j) {
int l=min(i-j, m);
if(j) {
ld x=T[i-1].nd; x/=m+1;
dp[i][j]=min(dp[i][j], dp[i-1][j-1]+x);
}
if(j<i) {
ld x=T[i-1].st; x/=l;
dp[i][j]=min(dp[i][j], dp[i-1][j]+x);
if(i-j>m) {
dp[i][j]=min(dp[i][j], dp[i-1][j]);
}
}
}
}
return dp[n][k-m];
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> k;
rep(i, n) {
cin >> T[i].nd >> T[i].st;
if(T[i].st==-1) T[i].st=INF;
}
sort(T, T+n);
ld ans=INF;
rep(i, k+1) ans=min(ans, solve(i));
cout << fixed << setprecision(3) << 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... |