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 double ld;
constexpr int MAXN = 5e2 + 8;
constexpr ld oo = 2e10;
ld dp[MAXN][MAXN];
pair<ld, ld> T[MAXN];
int n, k;
ld check(ld m){
for(int i = 0; i <= n; i++)
for(int j = 0; j <= k; j++)
dp[i][j] = oo;
dp[0][0] = 0;
for(int i = 1; i <= n; i++){
for(int j = 0; j <= min(k-(int)m, i); j++){
//dokladamy A
//if(j < i) dp[i][j] = min(dp[i][j], (j?(dp[i-1][j-1] + (T[i].second/(m+1)): oo));
//dokladamy B
//dp[i][j] = (dp[i-1][j] + (T[i].first/min((ld)(i-j), m+1)));
//min((j?(dp[i-1][j-1] + T[i].second/(m+1)): oo), ((i-j)?(dp[i-1][j] + T[i].first/min((ld)(i-j), m+1)): oo));
//dokladamy A
dp[i][j+1] = min(dp[i][j+1], dp[i-1][j] + (T[i].second/(m+1)));
//dokladamy B
if(i-j)
dp[i][j] = min(dp[i][j], dp[i-1][j] + ((i-j <= m)? (T[i].first/min((ld)(i-j), m+1)):0));
}
}
return dp[n][k-(int)m];
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for(int i = 1; i <= n; i++){
ld a, b;
cin >> a >> b;
if(b == -1) b = oo;
T[i] = {b, a};
}
sort(T+1, T+1+n);
ld best = oo;
for(int i = 0; i <= (k-1); i++)
best = min(best, check(i));
cout << fixed << setprecision(9) << best << "\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... |