Submission #806890

#TimeUsernameProblemLanguageResultExecution timeMemory
806890CookieLet's Win the Election (JOI22_ho_t3)C++14
72 / 100
38 ms3820 KiB
#include<bits/stdc++.h>
#include<fstream>
#pragma GCC optimize("Ofast,O3,unroll-loops")
#pragma GCC target("avx2")
using namespace std;
//ifstream fin("FEEDING.INP");
//ofstream fout("FEEDING.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const int base = 74;
const ll mod = 1e9 + 7, inf = 1e18, mxv = 1005, mxn = 2e5 + 5;
int n, k;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ld dp[505][505];
pll p[mxn + 1];
bool cmp(pll &a, pll &b){
    return(a.se < b.se);
}
ld get(int x){
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= min(i, x); j++){
            dp[i][j] = inf;
            int other = i - j;
            if(other <= k - x){
                dp[i][j] = dp[i - 1][j] + (ld)p[i].se / (other);
            }else{
                dp[i][j] = dp[i - 1][j];
            }
            other = min(other, k - x);
            if(j > 0){
                dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + (ld)p[i].fi / (k - x + 1));
                
            }
            
        }
    }
    return(dp[n][x]);
}
signed main()
{
     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        cin >> p[i].fi >> p[i].se;
        if(p[i].se == -1)p[i].se = 1e15;
    }
    sort(p + 1, p + n + 1, cmp);
    int l = 0, r = k;
    ld ans = inf;
    while(l <= r){
        int m1 = l + (r - l) / 3, m2 = r - (r - l) / 3;
        ld val1 = get(m1), val2 = get(m2);
        if(val1 < val2){
            ans = val1; r = m2 - 1;
        }else if(val1 > val2){
            ans = val2; l = m1 + 1;
        }else{
            r = m2 - 1; l = m1 + 1;
        }
    }
    cout << fixed << setprecision(10) << ans;
    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...