#include <bits/stdc++.h>
#define int long long
using namespace std;
string to_string(string s) { return s; }
template <typename T> string to_string(T v) {
bool first = true;
string res = "[";
for (const auto &x : v) {
if (!first)
res += ", ";
first = false;
res += to_string(x);
}
res += "]";
return res;
}
void dbg_out() { cout << endl; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {
cout << ' ' << to_string(H);
dbg_out(T...);
}
#ifdef DEBUG
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
using F = long double;
const int MAXN = 501;
const F INF = 1e18;
F dp[2][MAXN];
signed main(void) {
ios_base::sync_with_stdio(false);
cin.tie(0);
int nbEtats, nbVoulus;
cin >> nbEtats >> nbVoulus;
vector<pair<int, int>> etats(nbEtats);
int cnt = 0;
for (auto &[b, a] : etats) {
cin >> a >> b;
if (b == -1)
b = INF;
else
cnt++;
}
sort(etats.begin(), etats.end());
F sol = INF;
for (int c = 0; c <= cnt and c <= nbVoulus; ++c) {
for (int i = 0; i < 2; ++i)
for (int j = 0; j < MAXN; ++j)
dp[i][j] = INF;
dp[0][0] = 0;
F s = INF;
for (int nbVus = 0; nbVus <= nbEtats; ++nbVus) {
int cur = nbVus % 2;
int nxt = cur ^ 1;
for (int i = 0; i < MAXN; ++i)
dp[nxt][i] = INF;
for (int prisA = 0; prisA <= nbVus and prisA <= nbVoulus - c; ++prisA) {
int prisB = nbVus - prisA;
if (prisB > c)
continue;
F v = dp[cur][prisA];
if (prisB == c) {
vector<int> restants;
for (int i = nbVus; i < nbEtats; ++i)
restants.push_back(etats[i].second);
sort(restants.begin(), restants.end());
for (int i = 0; i < nbVoulus - nbVus; ++i)
v += restants[i] / (F)(c + 1);
s = min(s, v);
} else if (nbVus < nbEtats) {
auto [b, a] = etats[nbVus];
// on prend en A
dp[nxt][prisA + 1] = min(dp[nxt][prisA + 1], v + a / (F)(c + 1));
// on prend en b
dp[nxt][prisA] = min(dp[nxt][prisA], v + b / (F)(prisB + 1));
}
}
}
dbg(c, s);
sol = min(sol, s);
}
cout << setprecision(9) << fixed << sol << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
3 ms |
340 KB |
Output is correct |
9 |
Correct |
4 ms |
340 KB |
Output is correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
3 ms |
340 KB |
Output is correct |
9 |
Correct |
4 ms |
340 KB |
Output is correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
142 ms |
340 KB |
Output is correct |
13 |
Correct |
183 ms |
340 KB |
Output is correct |
14 |
Correct |
141 ms |
340 KB |
Output is correct |
15 |
Correct |
527 ms |
340 KB |
Output is correct |
16 |
Correct |
606 ms |
340 KB |
Output is correct |
17 |
Correct |
254 ms |
344 KB |
Output is correct |
18 |
Correct |
929 ms |
340 KB |
Output is correct |
19 |
Correct |
864 ms |
340 KB |
Output is correct |
20 |
Correct |
294 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
324 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
324 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
324 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
320 KB |
Output is correct |
27 |
Correct |
1 ms |
324 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
328 KB |
Output is correct |
30 |
Correct |
1 ms |
324 KB |
Output is correct |
31 |
Correct |
1 ms |
324 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
340 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 |
320 KB |
Output is correct |
37 |
Correct |
1 ms |
320 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
324 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
324 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
324 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
320 KB |
Output is correct |
27 |
Correct |
1 ms |
324 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
328 KB |
Output is correct |
30 |
Correct |
1 ms |
324 KB |
Output is correct |
31 |
Correct |
1 ms |
324 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
340 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 |
320 KB |
Output is correct |
37 |
Correct |
1 ms |
320 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
316 KB |
Output is correct |
41 |
Correct |
3 ms |
212 KB |
Output is correct |
42 |
Correct |
2 ms |
340 KB |
Output is correct |
43 |
Correct |
4 ms |
320 KB |
Output is correct |
44 |
Correct |
4 ms |
320 KB |
Output is correct |
45 |
Correct |
8 ms |
324 KB |
Output is correct |
46 |
Correct |
8 ms |
212 KB |
Output is correct |
47 |
Correct |
10 ms |
340 KB |
Output is correct |
48 |
Correct |
10 ms |
340 KB |
Output is correct |
49 |
Correct |
13 ms |
344 KB |
Output is correct |
50 |
Correct |
14 ms |
340 KB |
Output is correct |
51 |
Correct |
18 ms |
324 KB |
Output is correct |
52 |
Correct |
17 ms |
340 KB |
Output is correct |
53 |
Correct |
10 ms |
212 KB |
Output is correct |
54 |
Correct |
11 ms |
320 KB |
Output is correct |
55 |
Correct |
10 ms |
332 KB |
Output is correct |
56 |
Correct |
10 ms |
212 KB |
Output is correct |
57 |
Correct |
10 ms |
340 KB |
Output is correct |
58 |
Correct |
11 ms |
340 KB |
Output is correct |
59 |
Correct |
10 ms |
344 KB |
Output is correct |
60 |
Correct |
9 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1399 ms |
340 KB |
Output is correct |
2 |
Correct |
1400 ms |
340 KB |
Output is correct |
3 |
Correct |
1402 ms |
340 KB |
Output is correct |
4 |
Correct |
1399 ms |
340 KB |
Output is correct |
5 |
Correct |
1409 ms |
340 KB |
Output is correct |
6 |
Correct |
1419 ms |
324 KB |
Output is correct |
7 |
Correct |
1274 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
3 ms |
340 KB |
Output is correct |
9 |
Correct |
4 ms |
340 KB |
Output is correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
142 ms |
340 KB |
Output is correct |
13 |
Correct |
183 ms |
340 KB |
Output is correct |
14 |
Correct |
141 ms |
340 KB |
Output is correct |
15 |
Correct |
527 ms |
340 KB |
Output is correct |
16 |
Correct |
606 ms |
340 KB |
Output is correct |
17 |
Correct |
254 ms |
344 KB |
Output is correct |
18 |
Correct |
929 ms |
340 KB |
Output is correct |
19 |
Correct |
864 ms |
340 KB |
Output is correct |
20 |
Correct |
294 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 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 |
324 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
324 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
324 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
320 KB |
Output is correct |
47 |
Correct |
1 ms |
324 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
328 KB |
Output is correct |
50 |
Correct |
1 ms |
324 KB |
Output is correct |
51 |
Correct |
1 ms |
324 KB |
Output is correct |
52 |
Correct |
1 ms |
212 KB |
Output is correct |
53 |
Correct |
1 ms |
340 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 |
320 KB |
Output is correct |
57 |
Correct |
1 ms |
320 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 |
316 KB |
Output is correct |
61 |
Correct |
3 ms |
212 KB |
Output is correct |
62 |
Correct |
2 ms |
340 KB |
Output is correct |
63 |
Correct |
4 ms |
320 KB |
Output is correct |
64 |
Correct |
4 ms |
320 KB |
Output is correct |
65 |
Correct |
8 ms |
324 KB |
Output is correct |
66 |
Correct |
8 ms |
212 KB |
Output is correct |
67 |
Correct |
10 ms |
340 KB |
Output is correct |
68 |
Correct |
10 ms |
340 KB |
Output is correct |
69 |
Correct |
13 ms |
344 KB |
Output is correct |
70 |
Correct |
14 ms |
340 KB |
Output is correct |
71 |
Correct |
18 ms |
324 KB |
Output is correct |
72 |
Correct |
17 ms |
340 KB |
Output is correct |
73 |
Correct |
10 ms |
212 KB |
Output is correct |
74 |
Correct |
11 ms |
320 KB |
Output is correct |
75 |
Correct |
10 ms |
332 KB |
Output is correct |
76 |
Correct |
10 ms |
212 KB |
Output is correct |
77 |
Correct |
10 ms |
340 KB |
Output is correct |
78 |
Correct |
11 ms |
340 KB |
Output is correct |
79 |
Correct |
10 ms |
344 KB |
Output is correct |
80 |
Correct |
9 ms |
212 KB |
Output is correct |
81 |
Correct |
1399 ms |
340 KB |
Output is correct |
82 |
Correct |
1400 ms |
340 KB |
Output is correct |
83 |
Correct |
1402 ms |
340 KB |
Output is correct |
84 |
Correct |
1399 ms |
340 KB |
Output is correct |
85 |
Correct |
1409 ms |
340 KB |
Output is correct |
86 |
Correct |
1419 ms |
324 KB |
Output is correct |
87 |
Correct |
1274 ms |
340 KB |
Output is correct |
88 |
Correct |
45 ms |
340 KB |
Output is correct |
89 |
Correct |
46 ms |
344 KB |
Output is correct |
90 |
Correct |
190 ms |
340 KB |
Output is correct |
91 |
Correct |
187 ms |
340 KB |
Output is correct |
92 |
Correct |
562 ms |
340 KB |
Output is correct |
93 |
Correct |
580 ms |
344 KB |
Output is correct |
94 |
Correct |
1002 ms |
340 KB |
Output is correct |
95 |
Correct |
1014 ms |
340 KB |
Output is correct |
96 |
Correct |
1234 ms |
340 KB |
Output is correct |
97 |
Correct |
1264 ms |
340 KB |
Output is correct |
98 |
Correct |
880 ms |
340 KB |
Output is correct |
99 |
Correct |
887 ms |
344 KB |
Output is correct |
100 |
Correct |
881 ms |
352 KB |
Output is correct |
101 |
Correct |
909 ms |
460 KB |
Output is correct |
102 |
Correct |
843 ms |
340 KB |
Output is correct |
103 |
Correct |
822 ms |
332 KB |
Output is correct |
104 |
Correct |
792 ms |
340 KB |
Output is correct |
105 |
Correct |
490 ms |
340 KB |
Output is correct |