Submission #806282

#TimeUsernameProblemLanguageResultExecution timeMemory
806282vjudge1Let's Win the Election (JOI22_ho_t3)C++17
10 / 100
1 ms456 KiB
#ifdef Home
#define _GLIBCXX_DEBUG
#endif // Home

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

int use[555], T;

main() {
#ifdef Home
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // Home
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n, k;
    cin >> n >> k;
    vector < pair < int, int > > AB(n), A(n), B;
    for(int i = 0; i < n; ++ i) {
        cin >> AB[i].first >> AB[i].second;
        A[i] = {AB[i].first, i};
    }
    sort(A.begin(), A.end());
    for(int i = 0; i < n; ++ i) {
        if(AB[A[i].second].second != -1) {
            B.push_back({AB[A[i].second].second, i});
        }
    }
    sort(B.begin(), B.end(), [&](pair < int, int > a, pair < int, int > b) {
                return a.first == b.first ? A[a.second].first > A[b.second].first : a.first < b.first;
            });
    ld ans = 1e6, tmp, c;
    for(int t = 0; t <= (int)B.size(); ++ t) {
        if(t == k) {
            break;
        }
        ++ T;
        tmp = .0, c = 1;
        for(int i = 0; i < t; ++ i) {
            tmp += (ld)B[i].first / c;
            ++ c;
            use[B[i].second] = T;
        }
        for(int i = 0, j = k - t; i < n && j; ++ i) {
            if(use[i] != T) {
                -- j;
                tmp += (ld)A[i].first / c;
            }
        }
        ans = min(ans, tmp);
    }
    cout << fixed << setprecision(15) << ans;
} 

Compilation message (stderr)

Main.cpp:14:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   14 | main() {
      | ^~~~
#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...