제출 #1332502

#제출 시각아이디문제언어결과실행 시간메모리
1332502BolatuluLet's Win the Election (JOI22_ho_t3)C++20
10 / 100
7 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 = 2e18 + 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];
    }

    for (int i = 1; i <= k; i++) {
        dp[i][0] = dp[i - 1][0] + p[i].S;
        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)(j + 1));
        dp[i][i] = dp[i - 1][i - 1] + p[i].F / (db)i;
    }

    db res = inf;
    for (int i = 0; i <= k; i++) {
        for (int j = 0; j <= i; j++) {
            if (k - j <= n - i)
                res = min(res, dp[i][j] + mn[i + 1][k - j] / (db)(j + 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...