Submission #924030

# Submission time Handle Problem Language Result Execution time Memory
924030 2024-02-08T10:05:14 Z goodspeed0208 Let's Win the Election (JOI22_ho_t3) C++14
100 / 100
400 ms 3056 KB
#include<bits/stdc++.h>
#define pii pair<int, int>
#define INF 5000000
using namespace std;
 
bool cmp(pii a, pii b) {
	if (a.second == -1 && b.second == -1) return a.first < b.first;
	if (a.second == -1) return (1 > 2);
	if (b.second == -1) return (1 < 2);
	if (a.second == b.second) return a.first > b.first;
	return a.second < b.second;
}
 
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, K;
	cin >> n >> K;
	vector<pii>v(n+1);
	vector<double>a(n+1), b(n+1);
	for (int i = 1 ; i <=  n ;i++) cin >> v[i].first >> v[i].second;
	sort(v.begin()+1, v.end(), cmp);
	for (int i = 1 ; i <= n ;i++) a[i] = (double)v[i].first, b[i] = (double)v[i].second;
	//vector<vector<vector<double> > >dp(505, vector<vector<double> >(505, vector<double>(505, INF)) );
	//dp[0][0][1] = 0.0;
	
	double ans = INF;
    
    multiset<int>st;
    vector<double>w(n+2, 0);
    for (int i = n ; i >= 1 ; i--) {
        st.insert(a[i]);
        int k = 0;
        for (auto j : st) {
            if (k >= K-(i-1)) break;
            w[i] += j;
            k++;
            
        }
    }
    //for (int i = 1 ; i <= n ; i++) cout << w[i] << " ";
    //cout << "\n";
    ans = w[1];
    for (int help = 1 ; help <= K+1 ; help++) {
        vector<vector<double> >dp(505, vector<double>(505, INF));
        dp[0][1] = 0;
        //cout << "help" << " " << help << ": \n";
        for (int i = 1 ; i <= n ; i++) {//first i people
            //cout << i << ": ";
    		for (int k = 1 ; k <= min(i+1, help) ; k++) {// get how many people
    			dp[i][k] = dp[i-1][k] + (a[i] / help);
    			if (k > 1 && b[i] != -1) dp[i][k] = min(dp[i][k], dp[i-1][k-1] + b[i] / (k-1));
    			//cout << dp[i][k] <<" ";
    			
    			if (k == help) {
        		    ans = min(ans, dp[i][help] + w[i+1] / help);
        		    //cout << "ans: " << dp[i][help] << "+" << w[i+1] / help << "\n";
        		}
    			
    		}
    		//cout << "\n";
    	}
    	//for (int i = 0)
    }
        
	
	cout << fixed << setprecision(6) << ans << "\n";
	//for (auto &i : v) cout << i.first <<" " << i.second << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Correct 2 ms 2416 KB Output is correct
3 Correct 2 ms 2468 KB Output is correct
4 Correct 3 ms 2468 KB Output is correct
5 Correct 27 ms 2640 KB Output is correct
6 Correct 69 ms 2696 KB Output is correct
7 Correct 155 ms 2776 KB Output is correct
8 Correct 236 ms 2836 KB Output is correct
9 Correct 330 ms 2772 KB Output is correct
10 Correct 216 ms 2720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Correct 2 ms 2416 KB Output is correct
3 Correct 2 ms 2468 KB Output is correct
4 Correct 3 ms 2468 KB Output is correct
5 Correct 27 ms 2640 KB Output is correct
6 Correct 69 ms 2696 KB Output is correct
7 Correct 155 ms 2776 KB Output is correct
8 Correct 236 ms 2836 KB Output is correct
9 Correct 330 ms 2772 KB Output is correct
10 Correct 216 ms 2720 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 93 ms 2504 KB Output is correct
13 Correct 101 ms 2752 KB Output is correct
14 Correct 89 ms 2672 KB Output is correct
15 Correct 255 ms 2892 KB Output is correct
16 Correct 242 ms 2820 KB Output is correct
17 Correct 227 ms 2776 KB Output is correct
18 Correct 389 ms 2792 KB Output is correct
19 Correct 347 ms 2768 KB Output is correct
20 Correct 333 ms 2780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2392 KB Output is correct
2 Correct 2 ms 2424 KB Output is correct
3 Correct 3 ms 2468 KB Output is correct
4 Correct 3 ms 2464 KB Output is correct
5 Correct 4 ms 2468 KB Output is correct
6 Correct 4 ms 2468 KB Output is correct
7 Correct 5 ms 2468 KB Output is correct
8 Correct 4 ms 2464 KB Output is correct
9 Correct 4 ms 2464 KB Output is correct
10 Correct 4 ms 2464 KB Output is correct
11 Correct 4 ms 2468 KB Output is correct
12 Correct 4 ms 2468 KB Output is correct
13 Correct 4 ms 2468 KB Output is correct
14 Correct 4 ms 2468 KB Output is correct
15 Correct 5 ms 2460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2392 KB Output is correct
2 Correct 2 ms 2424 KB Output is correct
3 Correct 3 ms 2468 KB Output is correct
4 Correct 3 ms 2464 KB Output is correct
5 Correct 4 ms 2468 KB Output is correct
6 Correct 4 ms 2468 KB Output is correct
7 Correct 5 ms 2468 KB Output is correct
8 Correct 4 ms 2464 KB Output is correct
9 Correct 4 ms 2464 KB Output is correct
10 Correct 4 ms 2464 KB Output is correct
11 Correct 4 ms 2468 KB Output is correct
12 Correct 4 ms 2468 KB Output is correct
13 Correct 4 ms 2468 KB Output is correct
14 Correct 4 ms 2468 KB Output is correct
15 Correct 5 ms 2460 KB Output is correct
16 Correct 3 ms 2468 KB Output is correct
17 Correct 6 ms 2468 KB Output is correct
18 Correct 6 ms 2468 KB Output is correct
19 Correct 7 ms 2444 KB Output is correct
20 Correct 8 ms 2496 KB Output is correct
21 Correct 10 ms 2468 KB Output is correct
22 Correct 10 ms 2496 KB Output is correct
23 Correct 12 ms 2520 KB Output is correct
24 Correct 8 ms 2500 KB Output is correct
25 Correct 11 ms 2532 KB Output is correct
26 Correct 11 ms 2532 KB Output is correct
27 Correct 8 ms 2500 KB Output is correct
28 Correct 8 ms 2500 KB Output is correct
29 Correct 8 ms 2504 KB Output is correct
30 Correct 8 ms 2500 KB Output is correct
31 Correct 8 ms 2500 KB Output is correct
32 Correct 8 ms 2492 KB Output is correct
33 Correct 8 ms 2500 KB Output is correct
34 Correct 11 ms 2500 KB Output is correct
35 Correct 9 ms 2512 KB Output is correct
36 Correct 8 ms 2500 KB Output is correct
37 Correct 8 ms 2500 KB Output is correct
38 Correct 8 ms 2496 KB Output is correct
39 Correct 8 ms 2500 KB Output is correct
40 Correct 8 ms 2500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2392 KB Output is correct
2 Correct 2 ms 2424 KB Output is correct
3 Correct 3 ms 2468 KB Output is correct
4 Correct 3 ms 2464 KB Output is correct
5 Correct 4 ms 2468 KB Output is correct
6 Correct 4 ms 2468 KB Output is correct
7 Correct 5 ms 2468 KB Output is correct
8 Correct 4 ms 2464 KB Output is correct
9 Correct 4 ms 2464 KB Output is correct
10 Correct 4 ms 2464 KB Output is correct
11 Correct 4 ms 2468 KB Output is correct
12 Correct 4 ms 2468 KB Output is correct
13 Correct 4 ms 2468 KB Output is correct
14 Correct 4 ms 2468 KB Output is correct
15 Correct 5 ms 2460 KB Output is correct
16 Correct 3 ms 2468 KB Output is correct
17 Correct 6 ms 2468 KB Output is correct
18 Correct 6 ms 2468 KB Output is correct
19 Correct 7 ms 2444 KB Output is correct
20 Correct 8 ms 2496 KB Output is correct
21 Correct 10 ms 2468 KB Output is correct
22 Correct 10 ms 2496 KB Output is correct
23 Correct 12 ms 2520 KB Output is correct
24 Correct 8 ms 2500 KB Output is correct
25 Correct 11 ms 2532 KB Output is correct
26 Correct 11 ms 2532 KB Output is correct
27 Correct 8 ms 2500 KB Output is correct
28 Correct 8 ms 2500 KB Output is correct
29 Correct 8 ms 2504 KB Output is correct
30 Correct 8 ms 2500 KB Output is correct
31 Correct 8 ms 2500 KB Output is correct
32 Correct 8 ms 2492 KB Output is correct
33 Correct 8 ms 2500 KB Output is correct
34 Correct 11 ms 2500 KB Output is correct
35 Correct 9 ms 2512 KB Output is correct
36 Correct 8 ms 2500 KB Output is correct
37 Correct 8 ms 2500 KB Output is correct
38 Correct 8 ms 2496 KB Output is correct
39 Correct 8 ms 2500 KB Output is correct
40 Correct 8 ms 2500 KB Output is correct
41 Correct 9 ms 2500 KB Output is correct
42 Correct 9 ms 2504 KB Output is correct
43 Correct 16 ms 2560 KB Output is correct
44 Correct 16 ms 2536 KB Output is correct
45 Correct 29 ms 2600 KB Output is correct
46 Correct 27 ms 2660 KB Output is correct
47 Correct 35 ms 2664 KB Output is correct
48 Correct 34 ms 2472 KB Output is correct
49 Correct 43 ms 2472 KB Output is correct
50 Correct 42 ms 2660 KB Output is correct
51 Correct 59 ms 2724 KB Output is correct
52 Correct 52 ms 2648 KB Output is correct
53 Correct 35 ms 2476 KB Output is correct
54 Correct 37 ms 2680 KB Output is correct
55 Correct 39 ms 2660 KB Output is correct
56 Correct 33 ms 2472 KB Output is correct
57 Correct 34 ms 2676 KB Output is correct
58 Correct 34 ms 2628 KB Output is correct
59 Correct 34 ms 2692 KB Output is correct
60 Correct 35 ms 2692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 389 ms 2692 KB Output is correct
2 Correct 388 ms 2756 KB Output is correct
3 Correct 394 ms 2920 KB Output is correct
4 Correct 388 ms 2912 KB Output is correct
5 Correct 400 ms 2784 KB Output is correct
6 Correct 391 ms 2816 KB Output is correct
7 Correct 391 ms 2864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Correct 2 ms 2416 KB Output is correct
3 Correct 2 ms 2468 KB Output is correct
4 Correct 3 ms 2468 KB Output is correct
5 Correct 27 ms 2640 KB Output is correct
6 Correct 69 ms 2696 KB Output is correct
7 Correct 155 ms 2776 KB Output is correct
8 Correct 236 ms 2836 KB Output is correct
9 Correct 330 ms 2772 KB Output is correct
10 Correct 216 ms 2720 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 93 ms 2504 KB Output is correct
13 Correct 101 ms 2752 KB Output is correct
14 Correct 89 ms 2672 KB Output is correct
15 Correct 255 ms 2892 KB Output is correct
16 Correct 242 ms 2820 KB Output is correct
17 Correct 227 ms 2776 KB Output is correct
18 Correct 389 ms 2792 KB Output is correct
19 Correct 347 ms 2768 KB Output is correct
20 Correct 333 ms 2780 KB Output is correct
21 Correct 2 ms 2392 KB Output is correct
22 Correct 2 ms 2424 KB Output is correct
23 Correct 3 ms 2468 KB Output is correct
24 Correct 3 ms 2464 KB Output is correct
25 Correct 4 ms 2468 KB Output is correct
26 Correct 4 ms 2468 KB Output is correct
27 Correct 5 ms 2468 KB Output is correct
28 Correct 4 ms 2464 KB Output is correct
29 Correct 4 ms 2464 KB Output is correct
30 Correct 4 ms 2464 KB Output is correct
31 Correct 4 ms 2468 KB Output is correct
32 Correct 4 ms 2468 KB Output is correct
33 Correct 4 ms 2468 KB Output is correct
34 Correct 4 ms 2468 KB Output is correct
35 Correct 5 ms 2460 KB Output is correct
36 Correct 3 ms 2468 KB Output is correct
37 Correct 6 ms 2468 KB Output is correct
38 Correct 6 ms 2468 KB Output is correct
39 Correct 7 ms 2444 KB Output is correct
40 Correct 8 ms 2496 KB Output is correct
41 Correct 10 ms 2468 KB Output is correct
42 Correct 10 ms 2496 KB Output is correct
43 Correct 12 ms 2520 KB Output is correct
44 Correct 8 ms 2500 KB Output is correct
45 Correct 11 ms 2532 KB Output is correct
46 Correct 11 ms 2532 KB Output is correct
47 Correct 8 ms 2500 KB Output is correct
48 Correct 8 ms 2500 KB Output is correct
49 Correct 8 ms 2504 KB Output is correct
50 Correct 8 ms 2500 KB Output is correct
51 Correct 8 ms 2500 KB Output is correct
52 Correct 8 ms 2492 KB Output is correct
53 Correct 8 ms 2500 KB Output is correct
54 Correct 11 ms 2500 KB Output is correct
55 Correct 9 ms 2512 KB Output is correct
56 Correct 8 ms 2500 KB Output is correct
57 Correct 8 ms 2500 KB Output is correct
58 Correct 8 ms 2496 KB Output is correct
59 Correct 8 ms 2500 KB Output is correct
60 Correct 8 ms 2500 KB Output is correct
61 Correct 9 ms 2500 KB Output is correct
62 Correct 9 ms 2504 KB Output is correct
63 Correct 16 ms 2560 KB Output is correct
64 Correct 16 ms 2536 KB Output is correct
65 Correct 29 ms 2600 KB Output is correct
66 Correct 27 ms 2660 KB Output is correct
67 Correct 35 ms 2664 KB Output is correct
68 Correct 34 ms 2472 KB Output is correct
69 Correct 43 ms 2472 KB Output is correct
70 Correct 42 ms 2660 KB Output is correct
71 Correct 59 ms 2724 KB Output is correct
72 Correct 52 ms 2648 KB Output is correct
73 Correct 35 ms 2476 KB Output is correct
74 Correct 37 ms 2680 KB Output is correct
75 Correct 39 ms 2660 KB Output is correct
76 Correct 33 ms 2472 KB Output is correct
77 Correct 34 ms 2676 KB Output is correct
78 Correct 34 ms 2628 KB Output is correct
79 Correct 34 ms 2692 KB Output is correct
80 Correct 35 ms 2692 KB Output is correct
81 Correct 389 ms 2692 KB Output is correct
82 Correct 388 ms 2756 KB Output is correct
83 Correct 394 ms 2920 KB Output is correct
84 Correct 388 ms 2912 KB Output is correct
85 Correct 400 ms 2784 KB Output is correct
86 Correct 391 ms 2816 KB Output is correct
87 Correct 391 ms 2864 KB Output is correct
88 Correct 28 ms 2500 KB Output is correct
89 Correct 30 ms 2876 KB Output is correct
90 Correct 77 ms 2716 KB Output is correct
91 Correct 84 ms 3040 KB Output is correct
92 Correct 176 ms 2660 KB Output is correct
93 Correct 169 ms 2768 KB Output is correct
94 Correct 281 ms 2744 KB Output is correct
95 Correct 272 ms 2704 KB Output is correct
96 Correct 337 ms 2908 KB Output is correct
97 Correct 345 ms 2752 KB Output is correct
98 Correct 248 ms 2668 KB Output is correct
99 Correct 262 ms 2888 KB Output is correct
100 Correct 253 ms 2716 KB Output is correct
101 Correct 272 ms 3056 KB Output is correct
102 Correct 258 ms 2884 KB Output is correct
103 Correct 251 ms 2812 KB Output is correct
104 Correct 251 ms 2704 KB Output is correct
105 Correct 269 ms 2680 KB Output is correct