#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;
auto [b, a] = etats[nbVus];
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 {
// 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));
}
}
}
sol = min(sol, s);
}
cout << setprecision(15) << fixed << sol << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
2 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 |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
2 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 |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
143 ms |
340 KB |
Output is correct |
13 |
Correct |
180 ms |
340 KB |
Output is correct |
14 |
Correct |
135 ms |
464 KB |
Output is correct |
15 |
Correct |
520 ms |
340 KB |
Output is correct |
16 |
Correct |
602 ms |
340 KB |
Output is correct |
17 |
Correct |
249 ms |
460 KB |
Output is correct |
18 |
Correct |
921 ms |
340 KB |
Output is correct |
19 |
Correct |
833 ms |
340 KB |
Output is correct |
20 |
Correct |
292 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1472 ms |
340 KB |
Output is correct |
2 |
Correct |
1434 ms |
340 KB |
Output is correct |
3 |
Correct |
1392 ms |
340 KB |
Output is correct |
4 |
Incorrect |
1384 ms |
340 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
2 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 |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
143 ms |
340 KB |
Output is correct |
13 |
Correct |
180 ms |
340 KB |
Output is correct |
14 |
Correct |
135 ms |
464 KB |
Output is correct |
15 |
Correct |
520 ms |
340 KB |
Output is correct |
16 |
Correct |
602 ms |
340 KB |
Output is correct |
17 |
Correct |
249 ms |
460 KB |
Output is correct |
18 |
Correct |
921 ms |
340 KB |
Output is correct |
19 |
Correct |
833 ms |
340 KB |
Output is correct |
20 |
Correct |
292 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 |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
35 |
Halted |
0 ms |
0 KB |
- |