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 iter(a) a.begin(), a.end()
#define mp make_pair
#define F first
#define S second
#define eb emplace_back
#define lsort(a) sort(iter(a))
#define gsort(a) sort(iter(a), greater<>())
using namespace std;
typedef long long ll;
typedef long double ld;
using pii = pair<int, int>;
ll iceil(ll a, ll b){
return (a + b - 1) / b;
}
int n, k;
vector<int> a, b;
ld calc(int cnt){
vector<vector<ld>> dp(cnt + 1, vector<ld>(k + 1, 1e87));
dp[0][0] = 0;
for(int i = 1; i <= n; i++){
for(int c1 = cnt; c1 >= 0; c1--){
for(int c2 = k; c2 >= 0; c2--){
if(dp[c1][c2] == 1e87) continue;
if(c1 < cnt && b[i] != -1) dp[c1 + 1][c2] = min(dp[c1 + 1][c2], dp[c1][c2] + (ld)b[i] / (c1 + 1));
if(c2 < k) dp[c1][c2 + 1] = min(dp[c1][c2 + 1], dp[c1][c2] + (ld)a[i] / (cnt + 1));
}
}
}
return dp[cnt][k - cnt];
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
a.resize(n + 1);
b.resize(n + 1);
vector<pii> tmp(n + 1);
for(int i = 1; i <= n; i++) cin >> tmp[i].F >> tmp[i].S;
sort(tmp.begin() + 1, tmp.end(), [&](pii a, pii b){ return a.S < b.S; });
for(int i = 1; i <= n; i++) a[i] = tmp[i].F, b[i] = tmp[i].S;
ld ans = 1e87;
for(int i = 0; i <= k; i++) ans = min(ans, calc(i));
cout << fixed << setprecision(20) << ans << "\n";
return 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... |