#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
typedef long long int ll;
typedef long 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 110
#define M 1000000007 // 998244353
vector<pl> votes;
ll n, k;
ll take;
ld dp[NN][NN][NN]; //
ld rec(ll i, ll bs, ll vots) {
if (i == n) return vots + bs >= k and bs >= take ? 0: 1e18;
auto &DP = dp[i][bs][vots];
if (DP != DP) {
DP = 1e18;
DP = min(DP, rec(i+1, bs, vots));
DP = min(DP, rec(i+1, bs, vots+1) + ld(votes[i].V)/(1 + take));
if (~votes[i].K) DP = min(DP, rec(i+1, bs+1, vots) + ld(votes[i].K)/(1 + bs));
}
return DP;
}
#define SN 510
namespace keqn {
ld dp[SN][SN]; //
ld rec(ll i, ll bs) {
if (i == n) return bs >= take ? 0: 1e18;
auto &DP = dp[i][bs];
if (DP != DP) {
DP = 1e18;
DP = min(DP, rec(i+1, bs) + ld(votes[i].V)/(1 + take));
if (~votes[i].K) 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;
}
sort(A(votes));
ld ans = 1e18;
if (k == n) {
for (take = 0; take <= n; ++take) {
memset(keqn::dp, -1, sizeof(keqn::dp));
ans = min(ans, keqn::rec(0, 0));
}
cout << ans << '\n';
return 0;
}
for (take = 0; take <= n; take++) {
vector<bool> eaten(n);
ll cum = 0;
ld time = 0;
F(i, 0, n) if (cum < take) {
auto &[b, _] = votes[i];
if (b == -1) continue;
eaten[i] = 1;
time += ld(b)/(cum + 1);
cum++;
}
if (cum < take) continue;
vector<ll> ungotten;
F(i, 0, n) if (!eaten[i]) ungotten.push_back(votes[i].V);
sort(A(ungotten));
for (auto x: ungotten) if (cum < k) {
cum++;
time += ld(x)/(take+1);
}
// cout << "WHAT " << take << " " << time << endl;
ans = min(ans, time);
if (n <= 100) {
memset(dp, -1, sizeof dp);
ans = min(ans, rec(0, 0, 0));
// cout << "WTF " << ans << " " << take << " " << rec(0, 0, 0) << endl;
}
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
5 ms |
23132 KB |
Output is correct |
4 |
Correct |
5 ms |
23132 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
33 ms |
4768 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
5 ms |
23132 KB |
Output is correct |
4 |
Correct |
5 ms |
23132 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
33 ms |
4768 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
4696 KB |
Output is correct |
12 |
Correct |
3 ms |
348 KB |
Output is correct |
13 |
Correct |
3 ms |
348 KB |
Output is correct |
14 |
Correct |
2 ms |
600 KB |
Output is correct |
15 |
Correct |
3 ms |
600 KB |
Output is correct |
16 |
Correct |
3 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
1129 ms |
4952 KB |
Output is correct |
19 |
Correct |
452 ms |
4748 KB |
Output is correct |
20 |
Correct |
72 ms |
4700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23128 KB |
Output is correct |
2 |
Correct |
16 ms |
23132 KB |
Output is correct |
3 |
Correct |
13 ms |
23132 KB |
Output is correct |
4 |
Correct |
19 ms |
23128 KB |
Output is correct |
5 |
Correct |
18 ms |
23132 KB |
Output is correct |
6 |
Correct |
17 ms |
23144 KB |
Output is correct |
7 |
Correct |
2 ms |
4696 KB |
Output is correct |
8 |
Correct |
18 ms |
23132 KB |
Output is correct |
9 |
Correct |
18 ms |
23132 KB |
Output is correct |
10 |
Correct |
19 ms |
23140 KB |
Output is correct |
11 |
Correct |
18 ms |
23132 KB |
Output is correct |
12 |
Correct |
19 ms |
23132 KB |
Output is correct |
13 |
Correct |
18 ms |
23132 KB |
Output is correct |
14 |
Correct |
2 ms |
4696 KB |
Output is correct |
15 |
Correct |
2 ms |
4700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23128 KB |
Output is correct |
2 |
Correct |
16 ms |
23132 KB |
Output is correct |
3 |
Correct |
13 ms |
23132 KB |
Output is correct |
4 |
Correct |
19 ms |
23128 KB |
Output is correct |
5 |
Correct |
18 ms |
23132 KB |
Output is correct |
6 |
Correct |
17 ms |
23144 KB |
Output is correct |
7 |
Correct |
2 ms |
4696 KB |
Output is correct |
8 |
Correct |
18 ms |
23132 KB |
Output is correct |
9 |
Correct |
18 ms |
23132 KB |
Output is correct |
10 |
Correct |
19 ms |
23140 KB |
Output is correct |
11 |
Correct |
18 ms |
23132 KB |
Output is correct |
12 |
Correct |
19 ms |
23132 KB |
Output is correct |
13 |
Correct |
18 ms |
23132 KB |
Output is correct |
14 |
Correct |
2 ms |
4696 KB |
Output is correct |
15 |
Correct |
2 ms |
4700 KB |
Output is correct |
16 |
Correct |
41 ms |
23128 KB |
Output is correct |
17 |
Correct |
43 ms |
23128 KB |
Output is correct |
18 |
Correct |
36 ms |
23128 KB |
Output is correct |
19 |
Correct |
43 ms |
23128 KB |
Output is correct |
20 |
Correct |
36 ms |
23132 KB |
Output is correct |
21 |
Correct |
33 ms |
23132 KB |
Output is correct |
22 |
Correct |
45 ms |
23132 KB |
Output is correct |
23 |
Correct |
34 ms |
23132 KB |
Output is correct |
24 |
Correct |
27 ms |
23132 KB |
Output is correct |
25 |
Correct |
4 ms |
4700 KB |
Output is correct |
26 |
Correct |
3 ms |
4700 KB |
Output is correct |
27 |
Correct |
42 ms |
23120 KB |
Output is correct |
28 |
Correct |
44 ms |
23132 KB |
Output is correct |
29 |
Correct |
43 ms |
23132 KB |
Output is correct |
30 |
Correct |
47 ms |
23132 KB |
Output is correct |
31 |
Correct |
42 ms |
23128 KB |
Output is correct |
32 |
Correct |
44 ms |
23132 KB |
Output is correct |
33 |
Correct |
43 ms |
23132 KB |
Output is correct |
34 |
Correct |
45 ms |
23128 KB |
Output is correct |
35 |
Correct |
43 ms |
23128 KB |
Output is correct |
36 |
Correct |
45 ms |
23132 KB |
Output is correct |
37 |
Correct |
43 ms |
23128 KB |
Output is correct |
38 |
Correct |
45 ms |
23284 KB |
Output is correct |
39 |
Correct |
42 ms |
23128 KB |
Output is correct |
40 |
Correct |
42 ms |
23128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23128 KB |
Output is correct |
2 |
Correct |
16 ms |
23132 KB |
Output is correct |
3 |
Correct |
13 ms |
23132 KB |
Output is correct |
4 |
Correct |
19 ms |
23128 KB |
Output is correct |
5 |
Correct |
18 ms |
23132 KB |
Output is correct |
6 |
Correct |
17 ms |
23144 KB |
Output is correct |
7 |
Correct |
2 ms |
4696 KB |
Output is correct |
8 |
Correct |
18 ms |
23132 KB |
Output is correct |
9 |
Correct |
18 ms |
23132 KB |
Output is correct |
10 |
Correct |
19 ms |
23140 KB |
Output is correct |
11 |
Correct |
18 ms |
23132 KB |
Output is correct |
12 |
Correct |
19 ms |
23132 KB |
Output is correct |
13 |
Correct |
18 ms |
23132 KB |
Output is correct |
14 |
Correct |
2 ms |
4696 KB |
Output is correct |
15 |
Correct |
2 ms |
4700 KB |
Output is correct |
16 |
Correct |
41 ms |
23128 KB |
Output is correct |
17 |
Correct |
43 ms |
23128 KB |
Output is correct |
18 |
Correct |
36 ms |
23128 KB |
Output is correct |
19 |
Correct |
43 ms |
23128 KB |
Output is correct |
20 |
Correct |
36 ms |
23132 KB |
Output is correct |
21 |
Correct |
33 ms |
23132 KB |
Output is correct |
22 |
Correct |
45 ms |
23132 KB |
Output is correct |
23 |
Correct |
34 ms |
23132 KB |
Output is correct |
24 |
Correct |
27 ms |
23132 KB |
Output is correct |
25 |
Correct |
4 ms |
4700 KB |
Output is correct |
26 |
Correct |
3 ms |
4700 KB |
Output is correct |
27 |
Correct |
42 ms |
23120 KB |
Output is correct |
28 |
Correct |
44 ms |
23132 KB |
Output is correct |
29 |
Correct |
43 ms |
23132 KB |
Output is correct |
30 |
Correct |
47 ms |
23132 KB |
Output is correct |
31 |
Correct |
42 ms |
23128 KB |
Output is correct |
32 |
Correct |
44 ms |
23132 KB |
Output is correct |
33 |
Correct |
43 ms |
23132 KB |
Output is correct |
34 |
Correct |
45 ms |
23128 KB |
Output is correct |
35 |
Correct |
43 ms |
23128 KB |
Output is correct |
36 |
Correct |
45 ms |
23132 KB |
Output is correct |
37 |
Correct |
43 ms |
23128 KB |
Output is correct |
38 |
Correct |
45 ms |
23284 KB |
Output is correct |
39 |
Correct |
42 ms |
23128 KB |
Output is correct |
40 |
Correct |
42 ms |
23128 KB |
Output is correct |
41 |
Correct |
635 ms |
23132 KB |
Output is correct |
42 |
Correct |
565 ms |
23128 KB |
Output is correct |
43 |
Correct |
644 ms |
23132 KB |
Output is correct |
44 |
Correct |
488 ms |
23132 KB |
Output is correct |
45 |
Correct |
669 ms |
23132 KB |
Output is correct |
46 |
Correct |
517 ms |
23128 KB |
Output is correct |
47 |
Correct |
645 ms |
23380 KB |
Output is correct |
48 |
Correct |
462 ms |
23132 KB |
Output is correct |
49 |
Correct |
633 ms |
23128 KB |
Output is correct |
50 |
Correct |
548 ms |
23128 KB |
Output is correct |
51 |
Correct |
17 ms |
4700 KB |
Output is correct |
52 |
Correct |
17 ms |
5152 KB |
Output is correct |
53 |
Correct |
620 ms |
23132 KB |
Output is correct |
54 |
Correct |
638 ms |
23132 KB |
Output is correct |
55 |
Correct |
639 ms |
23376 KB |
Output is correct |
56 |
Correct |
638 ms |
23380 KB |
Output is correct |
57 |
Correct |
635 ms |
23124 KB |
Output is correct |
58 |
Correct |
675 ms |
23128 KB |
Output is correct |
59 |
Correct |
669 ms |
23132 KB |
Output is correct |
60 |
Correct |
624 ms |
23128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1143 ms |
4700 KB |
Output is correct |
2 |
Correct |
1192 ms |
4700 KB |
Output is correct |
3 |
Correct |
1128 ms |
4768 KB |
Output is correct |
4 |
Correct |
1130 ms |
4756 KB |
Output is correct |
5 |
Correct |
1124 ms |
4700 KB |
Output is correct |
6 |
Correct |
1122 ms |
4752 KB |
Output is correct |
7 |
Correct |
1114 ms |
4744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
5 ms |
23132 KB |
Output is correct |
4 |
Correct |
5 ms |
23132 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
33 ms |
4768 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
4696 KB |
Output is correct |
12 |
Correct |
3 ms |
348 KB |
Output is correct |
13 |
Correct |
3 ms |
348 KB |
Output is correct |
14 |
Correct |
2 ms |
600 KB |
Output is correct |
15 |
Correct |
3 ms |
600 KB |
Output is correct |
16 |
Correct |
3 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
1129 ms |
4952 KB |
Output is correct |
19 |
Correct |
452 ms |
4748 KB |
Output is correct |
20 |
Correct |
72 ms |
4700 KB |
Output is correct |
21 |
Correct |
14 ms |
23128 KB |
Output is correct |
22 |
Correct |
16 ms |
23132 KB |
Output is correct |
23 |
Correct |
13 ms |
23132 KB |
Output is correct |
24 |
Correct |
19 ms |
23128 KB |
Output is correct |
25 |
Correct |
18 ms |
23132 KB |
Output is correct |
26 |
Correct |
17 ms |
23144 KB |
Output is correct |
27 |
Correct |
2 ms |
4696 KB |
Output is correct |
28 |
Correct |
18 ms |
23132 KB |
Output is correct |
29 |
Correct |
18 ms |
23132 KB |
Output is correct |
30 |
Correct |
19 ms |
23140 KB |
Output is correct |
31 |
Correct |
18 ms |
23132 KB |
Output is correct |
32 |
Correct |
19 ms |
23132 KB |
Output is correct |
33 |
Correct |
18 ms |
23132 KB |
Output is correct |
34 |
Correct |
2 ms |
4696 KB |
Output is correct |
35 |
Correct |
2 ms |
4700 KB |
Output is correct |
36 |
Correct |
41 ms |
23128 KB |
Output is correct |
37 |
Correct |
43 ms |
23128 KB |
Output is correct |
38 |
Correct |
36 ms |
23128 KB |
Output is correct |
39 |
Correct |
43 ms |
23128 KB |
Output is correct |
40 |
Correct |
36 ms |
23132 KB |
Output is correct |
41 |
Correct |
33 ms |
23132 KB |
Output is correct |
42 |
Correct |
45 ms |
23132 KB |
Output is correct |
43 |
Correct |
34 ms |
23132 KB |
Output is correct |
44 |
Correct |
27 ms |
23132 KB |
Output is correct |
45 |
Correct |
4 ms |
4700 KB |
Output is correct |
46 |
Correct |
3 ms |
4700 KB |
Output is correct |
47 |
Correct |
42 ms |
23120 KB |
Output is correct |
48 |
Correct |
44 ms |
23132 KB |
Output is correct |
49 |
Correct |
43 ms |
23132 KB |
Output is correct |
50 |
Correct |
47 ms |
23132 KB |
Output is correct |
51 |
Correct |
42 ms |
23128 KB |
Output is correct |
52 |
Correct |
44 ms |
23132 KB |
Output is correct |
53 |
Correct |
43 ms |
23132 KB |
Output is correct |
54 |
Correct |
45 ms |
23128 KB |
Output is correct |
55 |
Correct |
43 ms |
23128 KB |
Output is correct |
56 |
Correct |
45 ms |
23132 KB |
Output is correct |
57 |
Correct |
43 ms |
23128 KB |
Output is correct |
58 |
Correct |
45 ms |
23284 KB |
Output is correct |
59 |
Correct |
42 ms |
23128 KB |
Output is correct |
60 |
Correct |
42 ms |
23128 KB |
Output is correct |
61 |
Correct |
635 ms |
23132 KB |
Output is correct |
62 |
Correct |
565 ms |
23128 KB |
Output is correct |
63 |
Correct |
644 ms |
23132 KB |
Output is correct |
64 |
Correct |
488 ms |
23132 KB |
Output is correct |
65 |
Correct |
669 ms |
23132 KB |
Output is correct |
66 |
Correct |
517 ms |
23128 KB |
Output is correct |
67 |
Correct |
645 ms |
23380 KB |
Output is correct |
68 |
Correct |
462 ms |
23132 KB |
Output is correct |
69 |
Correct |
633 ms |
23128 KB |
Output is correct |
70 |
Correct |
548 ms |
23128 KB |
Output is correct |
71 |
Correct |
17 ms |
4700 KB |
Output is correct |
72 |
Correct |
17 ms |
5152 KB |
Output is correct |
73 |
Correct |
620 ms |
23132 KB |
Output is correct |
74 |
Correct |
638 ms |
23132 KB |
Output is correct |
75 |
Correct |
639 ms |
23376 KB |
Output is correct |
76 |
Correct |
638 ms |
23380 KB |
Output is correct |
77 |
Correct |
635 ms |
23124 KB |
Output is correct |
78 |
Correct |
675 ms |
23128 KB |
Output is correct |
79 |
Correct |
669 ms |
23132 KB |
Output is correct |
80 |
Correct |
624 ms |
23128 KB |
Output is correct |
81 |
Correct |
1143 ms |
4700 KB |
Output is correct |
82 |
Correct |
1192 ms |
4700 KB |
Output is correct |
83 |
Correct |
1128 ms |
4768 KB |
Output is correct |
84 |
Correct |
1130 ms |
4756 KB |
Output is correct |
85 |
Correct |
1124 ms |
4700 KB |
Output is correct |
86 |
Correct |
1122 ms |
4752 KB |
Output is correct |
87 |
Correct |
1114 ms |
4744 KB |
Output is correct |
88 |
Incorrect |
5 ms |
344 KB |
Output isn't correct |
89 |
Halted |
0 ms |
0 KB |
- |