제출 #625292

#제출 시각아이디문제언어결과실행 시간메모리
625292dooompyLet's Win the Election (JOI22_ho_t3)C++17
10 / 100
2162 ms4492 KiB
#include "bits/stdc++.h"

using namespace std;

void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
    cout << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
    while (l != r) cout << *l << " \n"[++l == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
    return o >> a.first >> a.second;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
    return o << '(' << a.first << ", " << a.second << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
    bool is = false;
    for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
    return o << '}';
}

#ifdef local
#define test(args...) abc("[" + string(#args) + "]", args)
#else
#define test(args...) void(0)
#endif

using ll = long long;

vector<pair<int, int>> v;

int goal, n, k;

long double dp[505][505];

long double solve(int node, int ctcollab) {
    if (dp[node][ctcollab] != -1) return dp[node][ctcollab];

    if (node == n) return 1e9;

    int ctnorm = node - ctcollab;

    if (ctcollab == goal) {
        vector<pair<int, int>> cur;
        for (int i = node; i < n; i++) {
            cur.emplace_back(v[i]);
        }

        sort(cur.begin(), cur.end());
        long double ct = 0;

        for (int i = 0; i < k - node; i++) {
            ct += ((long double) cur[i].first) / (ctcollab + 1);
        }

        return dp[node][ctcollab] = ct;
    }

    long double ans = solve(node + 1, ctcollab + 1) + ((long double) v[node].second) / (ctcollab + 1);

    if (ctnorm + ctcollab < k) {
        ans = min(ans, solve(node + 1, ctcollab) + ((long double) v[node].first) / (goal + 1));
    }
//    cout << ans << endl;
    return dp[node][ctcollab] = ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
//    freopen("", "r", stdin);
//    freopen("", "w", stdout);
    cin >> n >> k;

    for (int i = 0; i < n; i++) {
        int a, b; cin >> a >> b;
        if (b == -1) b = 1e9;
        v.emplace_back(a, b);
    }

    sort(v.begin(), v.end(), [](pair<int, int> a, pair<int, int> b) {
        return a.second < b.second;
    });

    long double ans = 1e18;

    for (int i = 0; i < k; i++) {
        if (i >= 1 && v[i-1].second == 1e9) break;
        goal = i;
        fill(&dp[0][0], &dp[0][0] + sizeof(dp) / sizeof(dp[0][0]), -1);
        long double res = solve(0, 0);

        ans = min(ans, res);
    }

    cout << fixed << setprecision(10) << ans;
}
#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...