# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
795729 | 1bin | Let's Win the Election (JOI22_ho_t3) | C++14 | 187 ms | 2320 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>
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 = 1; i <= n; i++){
auto&[b, a] = v[i - 1];
for(int j = 0; j <= min(i, x); j++){
dp[i][j] = dp[i - 1][j] + 1.0 * a / (x + 1);
if(j && b != inf) dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + 1.0 * b / j);
}
}
if(dp[n][x] > 1e9 - eps) return 1e9;
vector<double> t;
int j = x;
for(int i = n; i; i--){
auto&[b, a] = v[i - 1];
if(abs(dp[i][j] - dp[i - 1][j] - 1.0 * a / (x + 1)) < eps) t.emplace_back(1.0 * a / (x + 1));
else ret += dp[i][j] - dp[i - 1][j - 1], j--;
}
sort(all(t));
for(int i = 0; i < k - x; i++) ret += t[i];
return ret;
}
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)
# | 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... |