제출 #1335892

#제출 시각아이디문제언어결과실행 시간메모리
1335892olocLet's Win the Election (JOI22_ho_t3)C++20
100 / 100
394 ms468 KiB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vect;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
#define pb push_back
#define f first
#define s second

bool cmp(const pii& a, const pii& b){
    if(a.f == -2) return true;
    if(b.f == -2) return false;
    if(a.s == -1) return false;
    if(b.s == -1) return true;
    return a.s < b.s;
}


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, k;
    cin >> n >> k;

    vector<pii> tab(n + 1);
    for(int i = 0; i < n; i++){
        cin >> tab[i].f >> tab[i].s;
    }
    tab[n] = {-2, 1e9};
    sort(tab.begin(), tab.end(), cmp);


    ld wyn = 1e18;

    for(int i = 1; i <= k; i++){
        vector<ld> dp(n + 1, 1e18);
        dp[0] = 0;
        for(int j = 1; j <= n; j++){
            for(int x = j - 1; x >= 0; x--){
                dp[x + 1] = min(dp[x + 1], dp[x] + ld(tab[j].f) / ld(i));
                int t = j - x;

                if(t < i){
                    if(tab[j].s != -1){
                        dp[x] += ld(tab[j].s) / ld(t);
                    }else{
                    	dp[x] = 1e18;
                    }
                }
            }
        }
        wyn = min(wyn, dp[k - i + 1]);
    }

    cout << fixed << setprecision(10) << wyn << "\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...