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;
#define all(v) v.begin(), v.end()
typedef long long ll;
const int NMAX = 1e5 + 5;
const int inf = 1e6;
const double eps = 1e-10;
int n, k, a, b;
double dp[505][505];
vector<pair<int, int>> v;
double solve(int x){
double ret = 0;
for(int i = 0; i <= n; i++)
for(int j = 0; j <= n; j++) dp[i][j] = 1e9;
dp[0][0] = 0;
for(int i = 0; i < n; i++){
auto&[b, a] = v[i];
for(int j = 0; j <= min(k - x, i); j++){
dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + 1.0 * a / (x + 1));
if(i - j < x) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1.0 * b / (i - j + 1));
else dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
}
}
return dp[n][k - x];
}
int main(void){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> k;
for(int i = 0; i < n; i++){
cin >> a >> b;
if(b == -1) b = inf;
v.emplace_back(b, a);
}
sort(all(v));
double ans = inf;
for(int i = 0; i <= k; i++) ans = min(ans, solve(i));
cout << fixed << setprecision(10) << ans;
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'double solve(int)':
Main.cpp:20:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
20 | auto&[b, a] = v[i];
| ^
Main.cpp:15:12: warning: unused variable 'ret' [-Wunused-variable]
15 | double ret = 0;
| ^~~
# | 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... |