Submission #587147

# Submission time Handle Problem Language Result Execution time Memory
587147 2022-07-01T11:41:20 Z rgnerdplayer Let's Win the Election (JOI22_ho_t3) C++17
0 / 100
190 ms 1380 KB
#include <bits/stdc++.h>
using namespace std;

using i64 = long long;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    auto solve = [&]() {
        int n, k;
        cin >> n >> k;

        vector<int> a(n), b(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i] >> b[i];
            if (b[i] == -1) {
                b[i] = 1e6;
            }
        }

        vector<int> ord(n);
        iota(ord.begin(), ord.end(), 0);
        sort(ord.begin(), ord.end(), [&](auto i, auto j) {
            return b[i] < b[j];
        });

        vector g(n + 1, vector<int>(k + 1, 1e9));
        g[n][0] = 0;

        for (int i = n - 1; i >= 0; i--) {
            g[i] = g[i + 1];
            for (int j = 0; j < k; j++) {
                g[i][j + 1] = min(g[i][j + 1], g[i + 1][j] + a[i]);
            }
        }

        double ans = g[0][k];

        for (int x = 0; x <= k; x++) {
            vector<double> f(x + 1, 1e9);
            f[0] = 0;
            for (int i = 0; i < k; i++) {
                int p = ord[i];
                vector<double> nf(x + 1, 1e9);
                for (int j = 0; j <= x; j++) {
                    nf[j] = min(nf[j], f[j] + 1.0 * a[p] / (x + 1));
                    if (j < x) {
                        nf[j + 1] = min(nf[j + 1], f[j] + 1.0 * b[p] / (j + 1));
                    }
                }
                f = nf;
                ans = min(ans, f[x] + 1.0 * g[i + 1][k - i - 1] / (x + 1));
            }
        }

        cout << fixed << setprecision(9) << ans << '\n';
    };
    
    solve();
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 4 ms 596 KB Output is correct
7 Incorrect 25 ms 920 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 4 ms 596 KB Output is correct
7 Incorrect 25 ms 920 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 190 ms 1380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 4 ms 596 KB Output is correct
7 Incorrect 25 ms 920 KB Output isn't correct
8 Halted 0 ms 0 KB -