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;
const int N = 500 + 10;
using ld = double;
void pmin(ld &a, ld c){a = min(a, c);}
struct cst{int a, b;} c[N];
int n, k;
ld odp[N][N], ndp[N][N];
signed main() {
iostream::sync_with_stdio(false);
cin.tie(0);cout.tie(0); cout << setprecision(10) << fixed;
cin >> n >> k;
for(int i = 0;i<n;i++)cin >> c[i + 1].a >> c[i + 1].b;
for(int i = 0;i<n;i++)if(c[i + 1].b == -1)c[i + 1].b = 1e9;
sort(c + 1, c + n + 1, [&](cst a, cst b){
if(a.b == b.b)return a.a < b.a;
return a.b < b.b;
});
for(int i = 0;i<=n;i++)for(int j = 0;j<=n;j++)odp[i][j] = ndp[i][j] = 1e8;
odp[0][0] = 0;
for(int i = 1;i<=n;i++){
for(int places = 0;places<=min(i, k);places++){
for(int collab = 0;collab<=places;collab++){
ndp[places][collab] = odp[places][collab];
if(places != 0){
pmin(ndp[places][collab], odp[places - 1][collab] + ((ld)c[i].a)/(collab + 1));
}
if(collab != 0 && c[i].b != 1e9){
pmin(ndp[places][collab], odp[places - 1][collab - 1] + ((ld)c[i].b)/(collab));
}
}
}
for(int c = 0;c<=i;c++){
for(int k = 0;k<=i;k++)odp[c][k] = ndp[c][k];
}
}
ld mn = 1e8;
for(int collab = 0;collab<=k;collab++)pmin(mn, ndp[k][collab]);
cout << mn << "\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... |