#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
typedef int ll;
typedef double ld;
typedef pair<ll, ll> pl;
typedef vector<ll> vl;
#define FD(i, r, l) for(ll i = r; i > (l); --i)
#define K first
#define V second
#define G(x) ll x; cin >> x;
#define GD(x) ld x; cin >> x;
#define GS(s) string s; cin >> s;
#define EX(x) { cout << x << '\n'; exit(0); }
#define A(a) (a).begin(), (a).end()
#define F(i, l, r) for (ll i = l; i < (r); ++i)
#define NN 510
vector<pl> votes;
vector<pl> votes2;
ll n, k;
ll take;
// The final observation is this:
// We can't actually "skip" votes in the optimal construction.
// Since there's absolutely no world in which we skip b[i] but take b[i+1].
// If we don't make b[i] a comrade, we MUST make him a voter.
ld dp[NN][NN];
ld dp2[NN][NN];
ld query(ll i, ll need) {
if (need <= 0) return 0;
return dp2[i][need];
}
ld rec(ll i, ll bs) {
if (bs == take) return query(i, k - i) / (1 + take);
if (i == n) return 1e9;
auto &DP = dp[i][bs];
if (DP != DP) {
DP = 1e9;
DP = min(DP, rec(i+1, bs) + ld(votes[i].V)/(1 + take));
DP = min(DP, rec(i+1, bs+1) + ld(votes[i].K)/(1 + bs));
}
return DP;
}
int main(){
// freopen("a.in", "r", stdin);
// freopen("a.out", "w", stdout);
ios_base::sync_with_stdio(false); cin.tie(0);
cout << fixed << setprecision(20);
cin >> n >> k;
votes.resize(n);
for (auto &[b, a]: votes) {
cin >> a >> b;
if (!~b) b = 1e9;
}
sort(A(votes));
F(i, 0, NN) F(j, 0, NN) dp2[i][j] = 1e12;
F(suff, 0, n+1) {
votes2 = votes;
sort(suff + A(votes2), [&](const pl &a, const pl &b) {
return a.V < b.V;
});
ld sm = 0;
ll take = 1;
for (auto it = votes2.begin() + suff; it != votes2.end(); it++) {
sm += it->V;
dp2[suff][take++] = sm;
}
}
ld ans = 1e9;
for (take = 0; take <= n; take++) {
memset(dp, -1, sizeof dp);
ans = min(ans, rec(0, 0));
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
4520 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
325 ms |
4528 KB |
Output is correct |
6 |
Correct |
346 ms |
4532 KB |
Output is correct |
7 |
Correct |
353 ms |
4440 KB |
Output is correct |
8 |
Correct |
341 ms |
4688 KB |
Output is correct |
9 |
Correct |
325 ms |
4444 KB |
Output is correct |
10 |
Correct |
334 ms |
4532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
4520 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
325 ms |
4528 KB |
Output is correct |
6 |
Correct |
346 ms |
4532 KB |
Output is correct |
7 |
Correct |
353 ms |
4440 KB |
Output is correct |
8 |
Correct |
341 ms |
4688 KB |
Output is correct |
9 |
Correct |
325 ms |
4444 KB |
Output is correct |
10 |
Correct |
334 ms |
4532 KB |
Output is correct |
11 |
Correct |
2 ms |
4444 KB |
Output is correct |
12 |
Correct |
326 ms |
4536 KB |
Output is correct |
13 |
Correct |
337 ms |
4532 KB |
Output is correct |
14 |
Correct |
331 ms |
4528 KB |
Output is correct |
15 |
Correct |
329 ms |
4532 KB |
Output is correct |
16 |
Correct |
356 ms |
4440 KB |
Output is correct |
17 |
Correct |
340 ms |
4532 KB |
Output is correct |
18 |
Correct |
335 ms |
4536 KB |
Output is correct |
19 |
Correct |
336 ms |
4532 KB |
Output is correct |
20 |
Correct |
332 ms |
4532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
4344 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
2 ms |
4444 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4444 KB |
Output is correct |
8 |
Correct |
2 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4444 KB |
Output is correct |
10 |
Correct |
2 ms |
4444 KB |
Output is correct |
11 |
Correct |
2 ms |
4444 KB |
Output is correct |
12 |
Correct |
2 ms |
4444 KB |
Output is correct |
13 |
Correct |
2 ms |
4444 KB |
Output is correct |
14 |
Correct |
2 ms |
4444 KB |
Output is correct |
15 |
Correct |
2 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
4344 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
2 ms |
4444 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4444 KB |
Output is correct |
8 |
Correct |
2 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4444 KB |
Output is correct |
10 |
Correct |
2 ms |
4444 KB |
Output is correct |
11 |
Correct |
2 ms |
4444 KB |
Output is correct |
12 |
Correct |
2 ms |
4444 KB |
Output is correct |
13 |
Correct |
2 ms |
4444 KB |
Output is correct |
14 |
Correct |
2 ms |
4444 KB |
Output is correct |
15 |
Correct |
2 ms |
4444 KB |
Output is correct |
16 |
Correct |
3 ms |
4440 KB |
Output is correct |
17 |
Correct |
3 ms |
4444 KB |
Output is correct |
18 |
Correct |
3 ms |
4440 KB |
Output is correct |
19 |
Correct |
2 ms |
4444 KB |
Output is correct |
20 |
Correct |
2 ms |
4444 KB |
Output is correct |
21 |
Correct |
2 ms |
4444 KB |
Output is correct |
22 |
Correct |
2 ms |
4444 KB |
Output is correct |
23 |
Correct |
2 ms |
4444 KB |
Output is correct |
24 |
Correct |
2 ms |
4444 KB |
Output is correct |
25 |
Correct |
2 ms |
4444 KB |
Output is correct |
26 |
Correct |
2 ms |
4444 KB |
Output is correct |
27 |
Correct |
2 ms |
4444 KB |
Output is correct |
28 |
Correct |
2 ms |
4444 KB |
Output is correct |
29 |
Correct |
2 ms |
4440 KB |
Output is correct |
30 |
Correct |
2 ms |
4444 KB |
Output is correct |
31 |
Correct |
3 ms |
4524 KB |
Output is correct |
32 |
Correct |
3 ms |
4444 KB |
Output is correct |
33 |
Correct |
2 ms |
4444 KB |
Output is correct |
34 |
Correct |
3 ms |
4444 KB |
Output is correct |
35 |
Correct |
3 ms |
4696 KB |
Output is correct |
36 |
Correct |
3 ms |
4440 KB |
Output is correct |
37 |
Correct |
3 ms |
4440 KB |
Output is correct |
38 |
Correct |
3 ms |
4440 KB |
Output is correct |
39 |
Correct |
2 ms |
4444 KB |
Output is correct |
40 |
Correct |
2 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
4344 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
2 ms |
4444 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4444 KB |
Output is correct |
8 |
Correct |
2 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4444 KB |
Output is correct |
10 |
Correct |
2 ms |
4444 KB |
Output is correct |
11 |
Correct |
2 ms |
4444 KB |
Output is correct |
12 |
Correct |
2 ms |
4444 KB |
Output is correct |
13 |
Correct |
2 ms |
4444 KB |
Output is correct |
14 |
Correct |
2 ms |
4444 KB |
Output is correct |
15 |
Correct |
2 ms |
4444 KB |
Output is correct |
16 |
Correct |
3 ms |
4440 KB |
Output is correct |
17 |
Correct |
3 ms |
4444 KB |
Output is correct |
18 |
Correct |
3 ms |
4440 KB |
Output is correct |
19 |
Correct |
2 ms |
4444 KB |
Output is correct |
20 |
Correct |
2 ms |
4444 KB |
Output is correct |
21 |
Correct |
2 ms |
4444 KB |
Output is correct |
22 |
Correct |
2 ms |
4444 KB |
Output is correct |
23 |
Correct |
2 ms |
4444 KB |
Output is correct |
24 |
Correct |
2 ms |
4444 KB |
Output is correct |
25 |
Correct |
2 ms |
4444 KB |
Output is correct |
26 |
Correct |
2 ms |
4444 KB |
Output is correct |
27 |
Correct |
2 ms |
4444 KB |
Output is correct |
28 |
Correct |
2 ms |
4444 KB |
Output is correct |
29 |
Correct |
2 ms |
4440 KB |
Output is correct |
30 |
Correct |
2 ms |
4444 KB |
Output is correct |
31 |
Correct |
3 ms |
4524 KB |
Output is correct |
32 |
Correct |
3 ms |
4444 KB |
Output is correct |
33 |
Correct |
2 ms |
4444 KB |
Output is correct |
34 |
Correct |
3 ms |
4444 KB |
Output is correct |
35 |
Correct |
3 ms |
4696 KB |
Output is correct |
36 |
Correct |
3 ms |
4440 KB |
Output is correct |
37 |
Correct |
3 ms |
4440 KB |
Output is correct |
38 |
Correct |
3 ms |
4440 KB |
Output is correct |
39 |
Correct |
2 ms |
4444 KB |
Output is correct |
40 |
Correct |
2 ms |
4444 KB |
Output is correct |
41 |
Correct |
9 ms |
4444 KB |
Output is correct |
42 |
Correct |
8 ms |
4440 KB |
Output is correct |
43 |
Correct |
8 ms |
4440 KB |
Output is correct |
44 |
Correct |
8 ms |
4444 KB |
Output is correct |
45 |
Correct |
8 ms |
4528 KB |
Output is correct |
46 |
Correct |
8 ms |
4444 KB |
Output is correct |
47 |
Correct |
9 ms |
4524 KB |
Output is correct |
48 |
Correct |
8 ms |
4444 KB |
Output is correct |
49 |
Correct |
8 ms |
4444 KB |
Output is correct |
50 |
Correct |
8 ms |
4444 KB |
Output is correct |
51 |
Correct |
8 ms |
4444 KB |
Output is correct |
52 |
Correct |
8 ms |
4444 KB |
Output is correct |
53 |
Correct |
8 ms |
4444 KB |
Output is correct |
54 |
Correct |
8 ms |
4444 KB |
Output is correct |
55 |
Correct |
8 ms |
4440 KB |
Output is correct |
56 |
Correct |
12 ms |
4696 KB |
Output is correct |
57 |
Correct |
8 ms |
4444 KB |
Output is correct |
58 |
Correct |
8 ms |
4468 KB |
Output is correct |
59 |
Correct |
8 ms |
4528 KB |
Output is correct |
60 |
Correct |
8 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
341 ms |
4532 KB |
Output is correct |
2 |
Correct |
349 ms |
4528 KB |
Output is correct |
3 |
Correct |
334 ms |
4532 KB |
Output is correct |
4 |
Correct |
345 ms |
4528 KB |
Output is correct |
5 |
Correct |
337 ms |
4440 KB |
Output is correct |
6 |
Correct |
354 ms |
4692 KB |
Output is correct |
7 |
Correct |
337 ms |
4484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
4520 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
325 ms |
4528 KB |
Output is correct |
6 |
Correct |
346 ms |
4532 KB |
Output is correct |
7 |
Correct |
353 ms |
4440 KB |
Output is correct |
8 |
Correct |
341 ms |
4688 KB |
Output is correct |
9 |
Correct |
325 ms |
4444 KB |
Output is correct |
10 |
Correct |
334 ms |
4532 KB |
Output is correct |
11 |
Correct |
2 ms |
4444 KB |
Output is correct |
12 |
Correct |
326 ms |
4536 KB |
Output is correct |
13 |
Correct |
337 ms |
4532 KB |
Output is correct |
14 |
Correct |
331 ms |
4528 KB |
Output is correct |
15 |
Correct |
329 ms |
4532 KB |
Output is correct |
16 |
Correct |
356 ms |
4440 KB |
Output is correct |
17 |
Correct |
340 ms |
4532 KB |
Output is correct |
18 |
Correct |
335 ms |
4536 KB |
Output is correct |
19 |
Correct |
336 ms |
4532 KB |
Output is correct |
20 |
Correct |
332 ms |
4532 KB |
Output is correct |
21 |
Correct |
2 ms |
4444 KB |
Output is correct |
22 |
Correct |
2 ms |
4444 KB |
Output is correct |
23 |
Correct |
2 ms |
4344 KB |
Output is correct |
24 |
Correct |
2 ms |
4444 KB |
Output is correct |
25 |
Correct |
2 ms |
4444 KB |
Output is correct |
26 |
Correct |
2 ms |
4444 KB |
Output is correct |
27 |
Correct |
2 ms |
4444 KB |
Output is correct |
28 |
Correct |
2 ms |
4444 KB |
Output is correct |
29 |
Correct |
2 ms |
4444 KB |
Output is correct |
30 |
Correct |
2 ms |
4444 KB |
Output is correct |
31 |
Correct |
2 ms |
4444 KB |
Output is correct |
32 |
Correct |
2 ms |
4444 KB |
Output is correct |
33 |
Correct |
2 ms |
4444 KB |
Output is correct |
34 |
Correct |
2 ms |
4444 KB |
Output is correct |
35 |
Correct |
2 ms |
4444 KB |
Output is correct |
36 |
Correct |
3 ms |
4440 KB |
Output is correct |
37 |
Correct |
3 ms |
4444 KB |
Output is correct |
38 |
Correct |
3 ms |
4440 KB |
Output is correct |
39 |
Correct |
2 ms |
4444 KB |
Output is correct |
40 |
Correct |
2 ms |
4444 KB |
Output is correct |
41 |
Correct |
2 ms |
4444 KB |
Output is correct |
42 |
Correct |
2 ms |
4444 KB |
Output is correct |
43 |
Correct |
2 ms |
4444 KB |
Output is correct |
44 |
Correct |
2 ms |
4444 KB |
Output is correct |
45 |
Correct |
2 ms |
4444 KB |
Output is correct |
46 |
Correct |
2 ms |
4444 KB |
Output is correct |
47 |
Correct |
2 ms |
4444 KB |
Output is correct |
48 |
Correct |
2 ms |
4444 KB |
Output is correct |
49 |
Correct |
2 ms |
4440 KB |
Output is correct |
50 |
Correct |
2 ms |
4444 KB |
Output is correct |
51 |
Correct |
3 ms |
4524 KB |
Output is correct |
52 |
Correct |
3 ms |
4444 KB |
Output is correct |
53 |
Correct |
2 ms |
4444 KB |
Output is correct |
54 |
Correct |
3 ms |
4444 KB |
Output is correct |
55 |
Correct |
3 ms |
4696 KB |
Output is correct |
56 |
Correct |
3 ms |
4440 KB |
Output is correct |
57 |
Correct |
3 ms |
4440 KB |
Output is correct |
58 |
Correct |
3 ms |
4440 KB |
Output is correct |
59 |
Correct |
2 ms |
4444 KB |
Output is correct |
60 |
Correct |
2 ms |
4444 KB |
Output is correct |
61 |
Correct |
9 ms |
4444 KB |
Output is correct |
62 |
Correct |
8 ms |
4440 KB |
Output is correct |
63 |
Correct |
8 ms |
4440 KB |
Output is correct |
64 |
Correct |
8 ms |
4444 KB |
Output is correct |
65 |
Correct |
8 ms |
4528 KB |
Output is correct |
66 |
Correct |
8 ms |
4444 KB |
Output is correct |
67 |
Correct |
9 ms |
4524 KB |
Output is correct |
68 |
Correct |
8 ms |
4444 KB |
Output is correct |
69 |
Correct |
8 ms |
4444 KB |
Output is correct |
70 |
Correct |
8 ms |
4444 KB |
Output is correct |
71 |
Correct |
8 ms |
4444 KB |
Output is correct |
72 |
Correct |
8 ms |
4444 KB |
Output is correct |
73 |
Correct |
8 ms |
4444 KB |
Output is correct |
74 |
Correct |
8 ms |
4444 KB |
Output is correct |
75 |
Correct |
8 ms |
4440 KB |
Output is correct |
76 |
Correct |
12 ms |
4696 KB |
Output is correct |
77 |
Correct |
8 ms |
4444 KB |
Output is correct |
78 |
Correct |
8 ms |
4468 KB |
Output is correct |
79 |
Correct |
8 ms |
4528 KB |
Output is correct |
80 |
Correct |
8 ms |
4444 KB |
Output is correct |
81 |
Correct |
341 ms |
4532 KB |
Output is correct |
82 |
Correct |
349 ms |
4528 KB |
Output is correct |
83 |
Correct |
334 ms |
4532 KB |
Output is correct |
84 |
Correct |
345 ms |
4528 KB |
Output is correct |
85 |
Correct |
337 ms |
4440 KB |
Output is correct |
86 |
Correct |
354 ms |
4692 KB |
Output is correct |
87 |
Correct |
337 ms |
4484 KB |
Output is correct |
88 |
Correct |
358 ms |
4548 KB |
Output is correct |
89 |
Correct |
357 ms |
4444 KB |
Output is correct |
90 |
Correct |
352 ms |
4532 KB |
Output is correct |
91 |
Correct |
338 ms |
4528 KB |
Output is correct |
92 |
Correct |
337 ms |
4528 KB |
Output is correct |
93 |
Correct |
339 ms |
4532 KB |
Output is correct |
94 |
Correct |
335 ms |
4532 KB |
Output is correct |
95 |
Correct |
331 ms |
4532 KB |
Output is correct |
96 |
Correct |
362 ms |
4688 KB |
Output is correct |
97 |
Correct |
337 ms |
4444 KB |
Output is correct |
98 |
Correct |
342 ms |
4544 KB |
Output is correct |
99 |
Correct |
349 ms |
4440 KB |
Output is correct |
100 |
Correct |
336 ms |
4440 KB |
Output is correct |
101 |
Correct |
331 ms |
4528 KB |
Output is correct |
102 |
Correct |
339 ms |
4528 KB |
Output is correct |
103 |
Correct |
332 ms |
4444 KB |
Output is correct |
104 |
Correct |
331 ms |
4532 KB |
Output is correct |
105 |
Correct |
325 ms |
4440 KB |
Output is correct |