Submission #698556

#TimeUsernameProblemLanguageResultExecution timeMemory
698556Danilo21Let's Win the Election (JOI22_ho_t3)C++14
10 / 100
1868 ms8324 KiB
#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define en '\n'
#define sp ' '
#define tb '\t'
#define ri(n) int n; cin >> n
#define rl(n) ll n; cin >> n
#define rs(s) string s; cin >> s
#define rc(c) char c; cin >> c
#define rv(v) for (auto &x : v) cin >> x
#define pven(v) for (auto x : v) cout << x << en
#define pv(v) for (auto x : v) cout << x << sp; cout << en
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yes cout << "YES" << en
#define no cout << "NO" << en
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define ssort(a, b) if (a < b) swap(a, b)
#define bitcnt(a) (__builtin_popcountll(a))
#define bithigh(a) (63-__builtin_clzll(a))
#define lg bithigh
#define highpow(a) (1LL << (ll)lg(a))

using namespace std;

const ll LINF = 4e18;
const int mxN = 5e2+10, INF = 2e9;
int n, m;
array<int, 2> a[mxN];
ld dp[2][mxN][mxN];

ld Div(ld x, ld y){ return x/y; }

void Solve(){

    cin >> n >> m;
    for (int i = 1; i <= n; i++){
        cin >> a[i][1] >> a[i][0];
        if (!~a[i][0]) a[i][0] = INF;
    }
    sort(a+1, a+n+1);
    for (int i = 1; i <= n; i++){
        swap(a[i][0], a[i][1]);
        if (a[i][1] == INF) a[i][1] = -1;
    }
    for (int j = 0; j <= n; j++)
        for (int t = 0; t <= n; t++)
            dp[0][j][t] = INF;
    dp[0][0][0] = 0;
    for (int i = 1; i <= n; i++){
        for (int j = 0; j <= n; j++){
            for (int t = 0; t <= n; t++){
                dp[1][j][t] = dp[0][j][t];
                if (j) smin(dp[1][j][t], dp[0][j-1][t] + Div(a[i][0], t+1));
                if (~a[i][1] && j && t) smin(dp[1][j][t], dp[0][j-1][t-1] + Div(a[i][1], t));
            }
        }
        for (int j = 0; j <= n; j++)
            for (int t = 0; t <= n; t++)
                dp[0][j][t] = dp[1][j][t];
    }
    ld ans = dp[0][m][0];
    for (int i = 1; i <= m; i++)
        smin(ans, dp[0][m][i]);
    cout << ans << en;
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0); cerr.tie(0);
    cout << setprecision(12) << fixed;
    cerr << setprecision(12) << fixed;
    cerr << "Started!" << endl;

    int t = 1;
    //cin >> t;
    while (t--)
        Solve();

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