# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1278007 | mingga | Let's Win the Election (JOI22_ho_t3) | C++20 | 162 ms | 2424 KiB |
// Author: caption_mingle
#include "bits/stdc++.h"
using namespace std;
#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define ll long long
const int mod = 1e9 + 7;
const int inf = 2e9;
const int N = 505;
int n, k;
double dp[N][N];
pair<int, int> d[N];
signed main() {
cin.tie(0) -> sync_with_stdio(0);
#define task ""
if(fopen(task ".INP", "r")) {
freopen(task ".INP", "r", stdin);
freopen(task ".OUT", "w", stdout);
}
cin >> n >> k;
for(int i = 1; i <= n; i++) {
int a, b; cin >> a >> b;
if(b == -1) b = inf;
d[i] = {b, a};
}
sort(d + 1, d + n + 1);
double ans = inf;
for(int i = 0; i <= k; i++) {
for(int j = 0; j <= n; j++) {
for(int t = 0; t <= k; t++) {
dp[j][t] = 2e9;
}
}
dp[0][0] = 0;
// cerr << "TURN " << i << ln;
for(int j = 1; j <= n; j++) {
for(int t = 0; t <= j; t++) {
if(t > 0) dp[j][t] = min(dp[j][t], dp[j - 1][t - 1] + d[j].se / (double)(i + 1));
if(j - t <= i) {
dp[j][t] = min(dp[j][t], dp[j - 1][t] + d[j].fi / (double)(j - t));
} else {
dp[j][t] = min(dp[j][t], dp[j - 1][t]);
}
// cerr << j << ' ' << t << ' ' << dp[j][t] << ln;
}
}
ans = min(ans, dp[n][k - i]);
}
cout << setprecision(6) << fixed << ans << ln;
cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}
Compilation message (stderr)
# | 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... |