Submission #1332506

#TimeUsernameProblemLanguageResultExecution timeMemory
1332506BolatuluLet's Win the Election (JOI22_ho_t3)C++20
100 / 100
82 ms6724 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define all(x) (x).begin(), (x).end()
#define md ((tl + tr) >> 1)
#define TL v + v, tl, md
#define TR v + v + 1, md + 1, tr
#define F first
#define S second
#define pii pair<int, int>
#define int ll

const int maxn = 5e5 + 7;
const ll inf = 1e9 + 7;
const double PI = atan2(0.0, -1.0);

int n, k, a[505], b[505], mn[505][505];
db dp[505][505];
vector<int> v[505];
pii p[505];

void solve() {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];
        if (b[i] == -1)
            b[i] = inf;
    }

    for (int i = 1; i <= n; i++)
        p[i] = {b[i], a[i]};
    sort(p + 1, p + n + 1);

    for (int i = n; i >= 1; i--) {
        v[i] = v[i + 1];
        v[i].push_back(p[i].S);
        sort(all(v[i]));
        for (int j = 0; j < v[i].size(); j++)
            mn[i][j + 1] = mn[i][j] + v[i][j];
    }

    db res = inf;
    for (int t = 0; t <= k; t++) {
        for (int i = 1; i <= k; i++) {
            dp[i][0] = dp[i - 1][0] + p[i].S / (db)(t + 1);
            for (int j = 1; j < i; j++)
                dp[i][j] = min(dp[i - 1][j - 1] + p[i].F / (db)j, dp[i - 1][j] + p[i].S / (db)(t + 1));
            dp[i][i] = dp[i - 1][i - 1] + p[i].F / (db)i;
        }
        for (int i = t; i <= k; i++)
            res = min(res, dp[i][t] + mn[i + 1][k - i] / (db)(t + 1));
    }

    cout << fixed << setprecision(10) << res;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int test = 1;
    // cin >> test;
    while (test--) {
        solve();
        // cout << '\n';
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...