Submission #734934

# Submission time Handle Problem Language Result Execution time Memory
734934 2023-05-03T09:38:44 Z Josia Let's Win the Election (JOI22_ho_t3) C++17
100 / 100
332 ms 2388 KB
#include <bits/stdc++.h>

using namespace std;

#define int int64_t




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

    int n, K; cin >> n >> K;
    vector<array<int, 3>> inputA(n);
    vector<array<int, 3>> inputB(n);


    for (int i=0; i<n; i++) {
        int a, b; cin >> a >> b;

        if (b == -1) b = 1e10;

        inputA[i]={a, b, i};
        inputB[i]={b, a, i};
    }

    sort(inputA.begin(), inputA.end());
    sort(inputB.begin(), inputB.end());

    // vector<bool> topK(n, 0);
    // for (int i = 0; i<K; i++) {
    //     topK[inputA[i][2]] = 1;
    // }




    double res = 1e10;

    array<array<double, 505>, 505> dp;
    for (int i=0; i<K; i++) {
        for (auto &a: dp) for (auto &b: a) b = 1e10;
        dp[0][0] = 0;
        for (int j=0; j<n; j++) {
            for (int k=0; k<=n; k++) {
                // cerr << dp[j][k] << " ";
                if (dp[j][k] == 1e10) continue;

                int colabs = j-k;

                int thisColab = 0;
                if (colabs < i) {
                    thisColab = inputB[j][0];
                }

                dp[j+1][k] = min(dp[j+1][k], dp[j][k]+(double)thisColab/(double)(colabs+1));
                dp[j+1][k+1] = min(dp[j+1][k+1], dp[j][k]+(double)inputB[j][1]/(double)(i+1));
            }
            // cerr << "\n";
        }
        // cerr << "\n";
        res = min(res, dp[n][K-i]);
    }



    // for (int colabs = 0; colabs<=K; colabs++) {
    //     for (int inTopK = 0; inTopK<=K; inTopK++) {
    //         double tmp = dp[n][inTopK][colabs];
    //         cerr << tmp << "\n";

    //         if (tmp == 1e10) continue;

    //         for  (int i = 0; i<K+inTopK; i++) {
    //             tmp += inputA[i][0];
    //         }

    //         res = min(res, tmp);
    //         cerr << "-" << tmp << "\n";
    //     }
    // }


    cout.precision(100);
    cout << res << "\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2260 KB Output is correct
2 Correct 2 ms 2312 KB Output is correct
3 Correct 2 ms 2260 KB Output is correct
4 Correct 2 ms 2260 KB Output is correct
5 Correct 16 ms 2260 KB Output is correct
6 Correct 36 ms 2260 KB Output is correct
7 Correct 68 ms 2260 KB Output is correct
8 Correct 118 ms 2320 KB Output is correct
9 Correct 142 ms 2320 KB Output is correct
10 Correct 102 ms 2260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2260 KB Output is correct
2 Correct 2 ms 2312 KB Output is correct
3 Correct 2 ms 2260 KB Output is correct
4 Correct 2 ms 2260 KB Output is correct
5 Correct 16 ms 2260 KB Output is correct
6 Correct 36 ms 2260 KB Output is correct
7 Correct 68 ms 2260 KB Output is correct
8 Correct 118 ms 2320 KB Output is correct
9 Correct 142 ms 2320 KB Output is correct
10 Correct 102 ms 2260 KB Output is correct
11 Correct 1 ms 2312 KB Output is correct
12 Correct 90 ms 2324 KB Output is correct
13 Correct 94 ms 2324 KB Output is correct
14 Correct 104 ms 2320 KB Output is correct
15 Correct 226 ms 2260 KB Output is correct
16 Correct 218 ms 2320 KB Output is correct
17 Correct 210 ms 2320 KB Output is correct
18 Correct 326 ms 2324 KB Output is correct
19 Correct 316 ms 2320 KB Output is correct
20 Correct 294 ms 2316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2260 KB Output is correct
2 Correct 2 ms 2260 KB Output is correct
3 Correct 2 ms 2260 KB Output is correct
4 Correct 2 ms 2308 KB Output is correct
5 Correct 2 ms 2260 KB Output is correct
6 Correct 2 ms 2260 KB Output is correct
7 Correct 3 ms 2388 KB Output is correct
8 Correct 2 ms 2260 KB Output is correct
9 Correct 2 ms 2304 KB Output is correct
10 Correct 2 ms 2260 KB Output is correct
11 Correct 2 ms 2260 KB Output is correct
12 Correct 2 ms 2260 KB Output is correct
13 Correct 2 ms 2312 KB Output is correct
14 Correct 2 ms 2308 KB Output is correct
15 Correct 2 ms 2260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2260 KB Output is correct
2 Correct 2 ms 2260 KB Output is correct
3 Correct 2 ms 2260 KB Output is correct
4 Correct 2 ms 2308 KB Output is correct
5 Correct 2 ms 2260 KB Output is correct
6 Correct 2 ms 2260 KB Output is correct
7 Correct 3 ms 2388 KB Output is correct
8 Correct 2 ms 2260 KB Output is correct
9 Correct 2 ms 2304 KB Output is correct
10 Correct 2 ms 2260 KB Output is correct
11 Correct 2 ms 2260 KB Output is correct
12 Correct 2 ms 2260 KB Output is correct
13 Correct 2 ms 2312 KB Output is correct
14 Correct 2 ms 2308 KB Output is correct
15 Correct 2 ms 2260 KB Output is correct
16 Correct 2 ms 2312 KB Output is correct
17 Correct 3 ms 2260 KB Output is correct
18 Correct 2 ms 2308 KB Output is correct
19 Correct 3 ms 2260 KB Output is correct
20 Correct 3 ms 2260 KB Output is correct
21 Correct 3 ms 2260 KB Output is correct
22 Correct 3 ms 2260 KB Output is correct
23 Correct 3 ms 2260 KB Output is correct
24 Correct 3 ms 2260 KB Output is correct
25 Correct 5 ms 2260 KB Output is correct
26 Correct 3 ms 2316 KB Output is correct
27 Correct 2 ms 2260 KB Output is correct
28 Correct 3 ms 2260 KB Output is correct
29 Correct 3 ms 2260 KB Output is correct
30 Correct 3 ms 2260 KB Output is correct
31 Correct 3 ms 2260 KB Output is correct
32 Correct 3 ms 2260 KB Output is correct
33 Correct 3 ms 2312 KB Output is correct
34 Correct 2 ms 2260 KB Output is correct
35 Correct 3 ms 2260 KB Output is correct
36 Correct 2 ms 2260 KB Output is correct
37 Correct 3 ms 2260 KB Output is correct
38 Correct 3 ms 2308 KB Output is correct
39 Correct 3 ms 2260 KB Output is correct
40 Correct 3 ms 2260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2260 KB Output is correct
2 Correct 2 ms 2260 KB Output is correct
3 Correct 2 ms 2260 KB Output is correct
4 Correct 2 ms 2308 KB Output is correct
5 Correct 2 ms 2260 KB Output is correct
6 Correct 2 ms 2260 KB Output is correct
7 Correct 3 ms 2388 KB Output is correct
8 Correct 2 ms 2260 KB Output is correct
9 Correct 2 ms 2304 KB Output is correct
10 Correct 2 ms 2260 KB Output is correct
11 Correct 2 ms 2260 KB Output is correct
12 Correct 2 ms 2260 KB Output is correct
13 Correct 2 ms 2312 KB Output is correct
14 Correct 2 ms 2308 KB Output is correct
15 Correct 2 ms 2260 KB Output is correct
16 Correct 2 ms 2312 KB Output is correct
17 Correct 3 ms 2260 KB Output is correct
18 Correct 2 ms 2308 KB Output is correct
19 Correct 3 ms 2260 KB Output is correct
20 Correct 3 ms 2260 KB Output is correct
21 Correct 3 ms 2260 KB Output is correct
22 Correct 3 ms 2260 KB Output is correct
23 Correct 3 ms 2260 KB Output is correct
24 Correct 3 ms 2260 KB Output is correct
25 Correct 5 ms 2260 KB Output is correct
26 Correct 3 ms 2316 KB Output is correct
27 Correct 2 ms 2260 KB Output is correct
28 Correct 3 ms 2260 KB Output is correct
29 Correct 3 ms 2260 KB Output is correct
30 Correct 3 ms 2260 KB Output is correct
31 Correct 3 ms 2260 KB Output is correct
32 Correct 3 ms 2260 KB Output is correct
33 Correct 3 ms 2312 KB Output is correct
34 Correct 2 ms 2260 KB Output is correct
35 Correct 3 ms 2260 KB Output is correct
36 Correct 2 ms 2260 KB Output is correct
37 Correct 3 ms 2260 KB Output is correct
38 Correct 3 ms 2308 KB Output is correct
39 Correct 3 ms 2260 KB Output is correct
40 Correct 3 ms 2260 KB Output is correct
41 Correct 4 ms 2260 KB Output is correct
42 Correct 4 ms 2260 KB Output is correct
43 Correct 5 ms 2260 KB Output is correct
44 Correct 5 ms 2260 KB Output is correct
45 Correct 7 ms 2260 KB Output is correct
46 Correct 7 ms 2312 KB Output is correct
47 Correct 10 ms 2316 KB Output is correct
48 Correct 10 ms 2260 KB Output is correct
49 Correct 13 ms 2260 KB Output is correct
50 Correct 13 ms 2320 KB Output is correct
51 Correct 20 ms 2260 KB Output is correct
52 Correct 13 ms 2316 KB Output is correct
53 Correct 10 ms 2260 KB Output is correct
54 Correct 10 ms 2308 KB Output is correct
55 Correct 9 ms 2308 KB Output is correct
56 Correct 9 ms 2316 KB Output is correct
57 Correct 9 ms 2316 KB Output is correct
58 Correct 9 ms 2312 KB Output is correct
59 Correct 9 ms 2260 KB Output is correct
60 Correct 9 ms 2260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 317 ms 2388 KB Output is correct
2 Correct 319 ms 2336 KB Output is correct
3 Correct 317 ms 2320 KB Output is correct
4 Correct 332 ms 2260 KB Output is correct
5 Correct 311 ms 2316 KB Output is correct
6 Correct 326 ms 2380 KB Output is correct
7 Correct 315 ms 2324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2260 KB Output is correct
2 Correct 2 ms 2312 KB Output is correct
3 Correct 2 ms 2260 KB Output is correct
4 Correct 2 ms 2260 KB Output is correct
5 Correct 16 ms 2260 KB Output is correct
6 Correct 36 ms 2260 KB Output is correct
7 Correct 68 ms 2260 KB Output is correct
8 Correct 118 ms 2320 KB Output is correct
9 Correct 142 ms 2320 KB Output is correct
10 Correct 102 ms 2260 KB Output is correct
11 Correct 1 ms 2312 KB Output is correct
12 Correct 90 ms 2324 KB Output is correct
13 Correct 94 ms 2324 KB Output is correct
14 Correct 104 ms 2320 KB Output is correct
15 Correct 226 ms 2260 KB Output is correct
16 Correct 218 ms 2320 KB Output is correct
17 Correct 210 ms 2320 KB Output is correct
18 Correct 326 ms 2324 KB Output is correct
19 Correct 316 ms 2320 KB Output is correct
20 Correct 294 ms 2316 KB Output is correct
21 Correct 1 ms 2260 KB Output is correct
22 Correct 2 ms 2260 KB Output is correct
23 Correct 2 ms 2260 KB Output is correct
24 Correct 2 ms 2308 KB Output is correct
25 Correct 2 ms 2260 KB Output is correct
26 Correct 2 ms 2260 KB Output is correct
27 Correct 3 ms 2388 KB Output is correct
28 Correct 2 ms 2260 KB Output is correct
29 Correct 2 ms 2304 KB Output is correct
30 Correct 2 ms 2260 KB Output is correct
31 Correct 2 ms 2260 KB Output is correct
32 Correct 2 ms 2260 KB Output is correct
33 Correct 2 ms 2312 KB Output is correct
34 Correct 2 ms 2308 KB Output is correct
35 Correct 2 ms 2260 KB Output is correct
36 Correct 2 ms 2312 KB Output is correct
37 Correct 3 ms 2260 KB Output is correct
38 Correct 2 ms 2308 KB Output is correct
39 Correct 3 ms 2260 KB Output is correct
40 Correct 3 ms 2260 KB Output is correct
41 Correct 3 ms 2260 KB Output is correct
42 Correct 3 ms 2260 KB Output is correct
43 Correct 3 ms 2260 KB Output is correct
44 Correct 3 ms 2260 KB Output is correct
45 Correct 5 ms 2260 KB Output is correct
46 Correct 3 ms 2316 KB Output is correct
47 Correct 2 ms 2260 KB Output is correct
48 Correct 3 ms 2260 KB Output is correct
49 Correct 3 ms 2260 KB Output is correct
50 Correct 3 ms 2260 KB Output is correct
51 Correct 3 ms 2260 KB Output is correct
52 Correct 3 ms 2260 KB Output is correct
53 Correct 3 ms 2312 KB Output is correct
54 Correct 2 ms 2260 KB Output is correct
55 Correct 3 ms 2260 KB Output is correct
56 Correct 2 ms 2260 KB Output is correct
57 Correct 3 ms 2260 KB Output is correct
58 Correct 3 ms 2308 KB Output is correct
59 Correct 3 ms 2260 KB Output is correct
60 Correct 3 ms 2260 KB Output is correct
61 Correct 4 ms 2260 KB Output is correct
62 Correct 4 ms 2260 KB Output is correct
63 Correct 5 ms 2260 KB Output is correct
64 Correct 5 ms 2260 KB Output is correct
65 Correct 7 ms 2260 KB Output is correct
66 Correct 7 ms 2312 KB Output is correct
67 Correct 10 ms 2316 KB Output is correct
68 Correct 10 ms 2260 KB Output is correct
69 Correct 13 ms 2260 KB Output is correct
70 Correct 13 ms 2320 KB Output is correct
71 Correct 20 ms 2260 KB Output is correct
72 Correct 13 ms 2316 KB Output is correct
73 Correct 10 ms 2260 KB Output is correct
74 Correct 10 ms 2308 KB Output is correct
75 Correct 9 ms 2308 KB Output is correct
76 Correct 9 ms 2316 KB Output is correct
77 Correct 9 ms 2316 KB Output is correct
78 Correct 9 ms 2312 KB Output is correct
79 Correct 9 ms 2260 KB Output is correct
80 Correct 9 ms 2260 KB Output is correct
81 Correct 317 ms 2388 KB Output is correct
82 Correct 319 ms 2336 KB Output is correct
83 Correct 317 ms 2320 KB Output is correct
84 Correct 332 ms 2260 KB Output is correct
85 Correct 311 ms 2316 KB Output is correct
86 Correct 326 ms 2380 KB Output is correct
87 Correct 315 ms 2324 KB Output is correct
88 Correct 31 ms 2260 KB Output is correct
89 Correct 31 ms 2260 KB Output is correct
90 Correct 78 ms 2260 KB Output is correct
91 Correct 75 ms 2320 KB Output is correct
92 Correct 169 ms 2260 KB Output is correct
93 Correct 153 ms 2332 KB Output is correct
94 Correct 238 ms 2324 KB Output is correct
95 Correct 233 ms 2260 KB Output is correct
96 Correct 288 ms 2316 KB Output is correct
97 Correct 281 ms 2332 KB Output is correct
98 Correct 223 ms 2260 KB Output is correct
99 Correct 224 ms 2320 KB Output is correct
100 Correct 219 ms 2260 KB Output is correct
101 Correct 231 ms 2320 KB Output is correct
102 Correct 227 ms 2388 KB Output is correct
103 Correct 214 ms 2320 KB Output is correct
104 Correct 226 ms 2260 KB Output is correct
105 Correct 217 ms 2260 KB Output is correct