# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
745719 | nguyentunglam | Let's Win the Election (JOI22_ho_t3) | C++17 | 821 ms | 5456 KiB |
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 fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;
const int N = 510;
pair<int, int> a[N];
int g[N][N];
long double f[N][N];
int main() {
#define task ""
cin.tie(0) -> sync_with_stdio(0);
if (fopen ("task.inp", "r")) {
freopen ("task.inp", "r", stdin);
freopen ("task.out", "w", stdout);
}
if (fopen (task".inp", "r")) {
freopen (task".inp", "r", stdin);
freopen (task".out", "w", stdout);
}
int n, k; cin >> n >> k;
for(int i = 1; i <= n; i++) {
cin >> a[i].fi >> a[i].se;
if (a[i].se == -1) a[i].se = 1e9;
}
sort(a + 1, a + n + 1, [] (const ii &x, const ii &y) {
if (x.se != y.se) return x.se < y.se;
return x.fi < y.fi;
});
long double res = 1e9;
for(int j = 1; j <= n; j++) g[n + 1][j] = 1e9, f[0][j] = 1e9;
for(int i = n; i >= 1; i--) {
g[i][0] = g[i + 1][0];
for(int j = 1; j <= n; j++) g[i][j] = min(g[i + 1][j], g[i + 1][j - 1] + a[i].fi);
}
for(int cnt = 0; cnt <= k; cnt++) {
for(int i = 1; i <= n; i++) {
f[i][0] = f[i - 1][0] + 1.0 * a[i].fi / (cnt + 1);
for(int j = 1; j <= n; j++) {
f[i][j] = min(f[i - 1][j] + 1.0 * a[i].fi / (cnt + 1), f[i - 1][j - 1] + 1.0 * a[i].se / j);
}
}
for(int i = 1; i <= k; i++) {
res = min(res, f[i][cnt] + 1.0 * g[i + 1][k - i] / (cnt + 1));
}
}
cout << fixed << setprecision(10) << res;
}
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... |