Submission #658799

# Submission time Handle Problem Language Result Execution time Memory
658799 2022-11-15T01:27:51 Z GrandTiger1729 Let's Win the Election (JOI22_ho_t3) C++17
100 / 100
198 ms 2396 KB
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
using namespace std;

const double INF = 1e9;
int main(){
    cin.tie(0)->sync_with_stdio(0);
    int n, K; cin >> n >> K;
    pair<double, double> a[n + 1]{};
    for (int i = 1; i <= n; i++){
        cin >> a[i].first >> a[i].second;
        if (a[i].second == -1){
            a[i].second = INF;
        }
    }
    sort(a + 1, a + n + 1, [&](pair<double, double> x, pair<double, double> y){
        return x.second < y.second;
    });
    double ans = INF;
    for (int t = 0; t < K; t++){
        double dp[n + 1][t + 1]{};
        for (int i = 0; i <= n; i++){
            fill(dp[i], dp[i] + t + 1, INF);
        }
        dp[0][0] = 0;
        for (int i = 1; i <= n; i++){
            for (int j = 1; j <= t; j++){
                dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + a[i].second / j);
            }
            for (int j = 0; j <= t; j++){
                dp[i][j] = min(dp[i][j], dp[i - 1][j] + a[i].first / (t + 1));
            }
        }
        double cur = 0;
        priority_queue<double, vector<double>, greater<double>> pq;
        for (int i = n; i > K; i--){
            pq.push(a[i].first);
        }
        double res = INF;
        for (int i = K; i >= t; i--){
            res = min(res, dp[i][t] + cur);
            pq.push(a[i].first);
            while (pq.size() > n - K){
                cur += pq.top() / (t + 1);
                pq.pop();
            }
        }
        ans = min(ans, res);
    }
    cout << fixed << setprecision(15) << ans;
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:45:30: warning: comparison of integer expressions of different signedness: 'std::priority_queue<double, std::vector<double>, std::greater<double> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   45 |             while (pq.size() > n - K){
      |                    ~~~~~~~~~~^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 3 ms 468 KB Output is correct
6 Correct 13 ms 792 KB Output is correct
7 Correct 52 ms 1228 KB Output is correct
8 Correct 100 ms 1740 KB Output is correct
9 Correct 173 ms 2248 KB Output is correct
10 Correct 92 ms 1596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 3 ms 468 KB Output is correct
6 Correct 13 ms 792 KB Output is correct
7 Correct 52 ms 1228 KB Output is correct
8 Correct 100 ms 1740 KB Output is correct
9 Correct 173 ms 2248 KB Output is correct
10 Correct 92 ms 1596 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 23 ms 780 KB Output is correct
13 Correct 18 ms 908 KB Output is correct
14 Correct 18 ms 904 KB Output is correct
15 Correct 92 ms 1768 KB Output is correct
16 Correct 91 ms 1612 KB Output is correct
17 Correct 90 ms 1688 KB Output is correct
18 Correct 169 ms 2212 KB Output is correct
19 Correct 183 ms 2148 KB Output is correct
20 Correct 182 ms 2248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 320 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 320 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 320 KB Output is correct
28 Correct 1 ms 320 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 320 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 320 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 320 KB Output is correct
28 Correct 1 ms 320 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 324 KB Output is correct
41 Correct 1 ms 316 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 312 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 320 KB Output is correct
49 Correct 2 ms 340 KB Output is correct
50 Correct 2 ms 324 KB Output is correct
51 Correct 2 ms 340 KB Output is correct
52 Correct 2 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 2 ms 316 KB Output is correct
55 Correct 2 ms 340 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 176 ms 2268 KB Output is correct
2 Correct 179 ms 2144 KB Output is correct
3 Correct 176 ms 2144 KB Output is correct
4 Correct 169 ms 2220 KB Output is correct
5 Correct 198 ms 2212 KB Output is correct
6 Correct 173 ms 2184 KB Output is correct
7 Correct 167 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 3 ms 468 KB Output is correct
6 Correct 13 ms 792 KB Output is correct
7 Correct 52 ms 1228 KB Output is correct
8 Correct 100 ms 1740 KB Output is correct
9 Correct 173 ms 2248 KB Output is correct
10 Correct 92 ms 1596 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 23 ms 780 KB Output is correct
13 Correct 18 ms 908 KB Output is correct
14 Correct 18 ms 904 KB Output is correct
15 Correct 92 ms 1768 KB Output is correct
16 Correct 91 ms 1612 KB Output is correct
17 Correct 90 ms 1688 KB Output is correct
18 Correct 169 ms 2212 KB Output is correct
19 Correct 183 ms 2148 KB Output is correct
20 Correct 182 ms 2248 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 316 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 316 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 316 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 316 KB Output is correct
35 Correct 1 ms 316 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 320 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 320 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 320 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 320 KB Output is correct
48 Correct 1 ms 320 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 212 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 324 KB Output is correct
61 Correct 1 ms 316 KB Output is correct
62 Correct 1 ms 212 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 312 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 1 ms 340 KB Output is correct
68 Correct 1 ms 320 KB Output is correct
69 Correct 2 ms 340 KB Output is correct
70 Correct 2 ms 324 KB Output is correct
71 Correct 2 ms 340 KB Output is correct
72 Correct 2 ms 340 KB Output is correct
73 Correct 1 ms 340 KB Output is correct
74 Correct 2 ms 316 KB Output is correct
75 Correct 2 ms 340 KB Output is correct
76 Correct 1 ms 340 KB Output is correct
77 Correct 1 ms 340 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 1 ms 340 KB Output is correct
80 Correct 1 ms 340 KB Output is correct
81 Correct 176 ms 2268 KB Output is correct
82 Correct 179 ms 2144 KB Output is correct
83 Correct 176 ms 2144 KB Output is correct
84 Correct 169 ms 2220 KB Output is correct
85 Correct 198 ms 2212 KB Output is correct
86 Correct 173 ms 2184 KB Output is correct
87 Correct 167 ms 2396 KB Output is correct
88 Correct 3 ms 468 KB Output is correct
89 Correct 3 ms 468 KB Output is correct
90 Correct 13 ms 724 KB Output is correct
91 Correct 14 ms 712 KB Output is correct
92 Correct 51 ms 1212 KB Output is correct
93 Correct 48 ms 1176 KB Output is correct
94 Correct 100 ms 1756 KB Output is correct
95 Correct 102 ms 1764 KB Output is correct
96 Correct 143 ms 2068 KB Output is correct
97 Correct 138 ms 2068 KB Output is correct
98 Correct 93 ms 1624 KB Output is correct
99 Correct 109 ms 1640 KB Output is correct
100 Correct 87 ms 1612 KB Output is correct
101 Correct 93 ms 1780 KB Output is correct
102 Correct 86 ms 1676 KB Output is correct
103 Correct 93 ms 1672 KB Output is correct
104 Correct 85 ms 1640 KB Output is correct
105 Correct 86 ms 1760 KB Output is correct