Submission #624899

#TimeUsernameProblemLanguageResultExecution timeMemory
624899dooompyLet's Win the Election (JOI22_ho_t3)C++17
10 / 100
8 ms300 KiB
#include <bits/stdc++.h>

using namespace std;

vector<pair<int, int>> v;

int main() {
    int n, k; 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) {
        if (a.second == b.second) {
            return a.first < b.first;
        }
        return a.second < b.second;
    });

    double ans = 2e9;

    for (int i = 0; i <= k; i++) {
        // take b up to here

        double total = 0;

        for (int j = 0; j < i; j++) {
            total += (double) (v[j].second) / (double) (j + 1);
        }

        vector<pair<int, int>> cur;
        for (int j = i; j < n; j++) {
            cur.push_back(v[j]);
        }

        sort(cur.begin(), cur.end());

        for (int j = 0; j < k - i; j++) {
            total += (double) (cur[j].first) / (double) (i + 1);
        }

        ans = min(ans, total);
    }

    cout << 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...