Submission #1043425

# Submission time Handle Problem Language Result Execution time Memory
1043425 2024-08-04T09:23:41 Z Lucpp Let's Win the Election (JOI22_ho_t3) C++17
100 / 100
362 ms 2816 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define sz(x) (int)size(x)
#define all(x) (x).begin(), (x).end()
constexpr double inf = 1e18;

double pmin(double &a, double b){
	return a = min(a, b);
}

int main(){
	cin.tie(0)->sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	vector<double> a(n), b(n);
	for(int i = 0; i < n; i++){
		cin >> a[i] >> b[i];
		if(b[i] < 0) b[i] = inf;
	}
	{
		vector<int> ord(n);
		for(int i = 0; i < n; i++) ord[i] = i;
		sort(all(ord), [&](int i, int j){return b[i] < b[j];});
		vector<double> a2(n), b2(n);
		for(int i = 0; i < n; i++) a2[i] = a[ord[i]], b2[i] = b[ord[i]];
		a = a2, b = b2;
	}
	vector<int> ordA(n);
	for(int i = 0; i < n; i++) ordA[i] = i;
	sort(all(ordA), [&](int i, int j){return a[i] < a[j];});
	double ans = inf;
	for(int l = 0; l <= k; l++){
		vector<vector<double>> dp(k+1, vector<double>(l+1, inf));
		dp[0][0] = 0;
		for(int i = 0; i < k; i++){
			for(int j = 0; j <= l; j++){
				if(j < l) pmin(dp[i+1][j+1], dp[i][j] + b[i] / (1+j));
				pmin(dp[i+1][j], dp[i][j] + a[i] / (1+l));
			}
		}
		for(int i = l; i <= k; i++){
			double val = dp[i][l];
			int cnt = i;
			for(int j : ordA){
				if(j >= i && cnt < k){
					val += a[j] / (1+l);
					cnt++;
				}
			}
			ans = min(ans, val);
		}
	}
	cout << setprecision(6) << fixed << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 6 ms 604 KB Output is correct
7 Correct 44 ms 1184 KB Output is correct
8 Correct 143 ms 1768 KB Output is correct
9 Correct 310 ms 2812 KB Output is correct
10 Correct 118 ms 1996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 6 ms 604 KB Output is correct
7 Correct 44 ms 1184 KB Output is correct
8 Correct 143 ms 1768 KB Output is correct
9 Correct 310 ms 2812 KB Output is correct
10 Correct 118 ms 1996 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 12 ms 876 KB Output is correct
13 Correct 10 ms 892 KB Output is correct
14 Correct 11 ms 872 KB Output is correct
15 Correct 114 ms 2004 KB Output is correct
16 Correct 117 ms 1648 KB Output is correct
17 Correct 124 ms 2012 KB Output is correct
18 Correct 311 ms 2780 KB Output is correct
19 Correct 318 ms 2632 KB Output is correct
20 Correct 362 ms 2756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 596 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 596 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 596 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 1 ms 344 KB Output is correct
44 Correct 1 ms 344 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 2 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 604 KB Output is correct
51 Correct 3 ms 604 KB Output is correct
52 Correct 2 ms 604 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 2 ms 384 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 2 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 338 ms 2768 KB Output is correct
2 Correct 311 ms 2632 KB Output is correct
3 Correct 336 ms 2816 KB Output is correct
4 Correct 312 ms 2676 KB Output is correct
5 Correct 329 ms 2760 KB Output is correct
6 Correct 317 ms 2704 KB Output is correct
7 Correct 331 ms 2708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 6 ms 604 KB Output is correct
7 Correct 44 ms 1184 KB Output is correct
8 Correct 143 ms 1768 KB Output is correct
9 Correct 310 ms 2812 KB Output is correct
10 Correct 118 ms 1996 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 12 ms 876 KB Output is correct
13 Correct 10 ms 892 KB Output is correct
14 Correct 11 ms 872 KB Output is correct
15 Correct 114 ms 2004 KB Output is correct
16 Correct 117 ms 1648 KB Output is correct
17 Correct 124 ms 2012 KB Output is correct
18 Correct 311 ms 2780 KB Output is correct
19 Correct 318 ms 2632 KB Output is correct
20 Correct 362 ms 2756 KB Output is correct
21 Correct 0 ms 596 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 0 ms 344 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 344 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 344 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 0 ms 344 KB Output is correct
63 Correct 1 ms 344 KB Output is correct
64 Correct 1 ms 344 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Correct 1 ms 344 KB Output is correct
67 Correct 2 ms 348 KB Output is correct
68 Correct 1 ms 348 KB Output is correct
69 Correct 1 ms 348 KB Output is correct
70 Correct 1 ms 604 KB Output is correct
71 Correct 3 ms 604 KB Output is correct
72 Correct 2 ms 604 KB Output is correct
73 Correct 1 ms 348 KB Output is correct
74 Correct 2 ms 384 KB Output is correct
75 Correct 1 ms 348 KB Output is correct
76 Correct 1 ms 348 KB Output is correct
77 Correct 1 ms 348 KB Output is correct
78 Correct 1 ms 348 KB Output is correct
79 Correct 2 ms 348 KB Output is correct
80 Correct 1 ms 348 KB Output is correct
81 Correct 338 ms 2768 KB Output is correct
82 Correct 311 ms 2632 KB Output is correct
83 Correct 336 ms 2816 KB Output is correct
84 Correct 312 ms 2676 KB Output is correct
85 Correct 329 ms 2760 KB Output is correct
86 Correct 317 ms 2704 KB Output is correct
87 Correct 331 ms 2708 KB Output is correct
88 Correct 2 ms 344 KB Output is correct
89 Correct 1 ms 348 KB Output is correct
90 Correct 7 ms 856 KB Output is correct
91 Correct 7 ms 608 KB Output is correct
92 Correct 46 ms 1168 KB Output is correct
93 Correct 46 ms 1172 KB Output is correct
94 Correct 144 ms 1776 KB Output is correct
95 Correct 145 ms 1784 KB Output is correct
96 Correct 252 ms 2488 KB Output is correct
97 Correct 244 ms 2340 KB Output is correct
98 Correct 117 ms 1864 KB Output is correct
99 Correct 124 ms 1804 KB Output is correct
100 Correct 139 ms 1864 KB Output is correct
101 Correct 126 ms 1660 KB Output is correct
102 Correct 125 ms 1988 KB Output is correct
103 Correct 122 ms 1616 KB Output is correct
104 Correct 118 ms 1796 KB Output is correct
105 Correct 114 ms 1644 KB Output is correct