#include <bits/stdc++.h>
//#define double long double
#define mp(x...) array<int, 2>({x})
using namespace std;
constexpr static int INF = 1e8;
constexpr static int MXSIZE = 1000;
bitset<MXSIZE> added;
array<int, 2> a[MXSIZE];
array<int, 3> b[MXSIZE];
int n, k;
double calculate(int cc)
{
int count = 0;
double cost = 0;
for (int i = 0; i < cc; i++)
{
cost += static_cast<double>(b[i][0]) / (i+1);
count++;
}
for (int i = 0; i < n && count < k; i++)
{
if (added[a[i][1]])
continue;
cost += static_cast<double>(a[i][0]) / (cc+1);
count++;
}
assert(count == k);
return cost;
}
constexpr static int MXSIZE2 = 101;
double dp[MXSIZE2][MXSIZE2][MXSIZE2][MXSIZE2]; // Position, expected value, filled count, current value
array<int, 2> v[MXSIZE2];
void subtask2()
{
cin >> k;
for (int i = 0; i < n; i++)
{
int aa, bb;
cin >> aa >> bb;
bb = (bb == -1) ? INF : bb;
v[i] = mp(bb, aa);
}
for (int i = 0; i < MXSIZE2; i++)
for (int j = 0; j < MXSIZE2; j++)
for (int l = 0; l < MXSIZE2; l++)
for (int w = 0; w < MXSIZE2; w++)
if (w != 0 || l != 0)
dp[i][j][l][w] = INF;
sort(v, v + n);
for (int i = n-1; i >= 0; i--)
{
double bb = v[i][0], aa = v[i][1];
for (int j = 0; j <= k; j++)
{
for (int l = 0; l <= k; l++)
{
for (int w = 0; w <= j; w++)
{
dp[i][j][l][w] = dp[i+1][j][l][w];
if (l != 0)
dp[i][j][l][w] = min({dp[i][j][l][w], (w > 0) ? (dp[i+1][j][l-1][w-1] + (bb / (j-w+1))) : INF, dp[i+1][j][l-1][w] + (aa / (j+1))} );
}
}
}
}
double best = INF;
for (int i = 0; i <= n; i++)
best = min(best, dp[0][i][k][i]);
cout << fixed;
cout << setprecision(20);
cout << best << "\n";
}
int main()
{
cin >> n;
if (n < 100)
{
subtask2();
return 0;
}
cin >> k;
for (int i = 0; i < n; i++)
{
int aa, bb;
cin >> aa >> bb;
a[i] = mp(aa, i);
bb = bb == -1 ? INF : bb;
b[i] = array<int, 3>({bb, -aa, i});
}
sort(a, a + n);
sort(b, b + n);
double best = INF;
for (int i = 0; i <= k && (i == 0 || b[i-1][0] != INF); i++)
{
if (i > 0)
added[b[i-1][2]] = true;
best = min(best, calculate(i));
}
cout << fixed;
cout << setprecision(20);
cout << best << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
391 ms |
814812 KB |
Output is correct |
2 |
Correct |
306 ms |
814760 KB |
Output is correct |
3 |
Correct |
312 ms |
814816 KB |
Output is correct |
4 |
Correct |
318 ms |
814940 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
391 ms |
814812 KB |
Output is correct |
2 |
Correct |
306 ms |
814760 KB |
Output is correct |
3 |
Correct |
312 ms |
814816 KB |
Output is correct |
4 |
Correct |
318 ms |
814940 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 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 |
320 ms |
814808 KB |
Output is correct |
12 |
Correct |
1 ms |
256 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 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 |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
307 ms |
814780 KB |
Output is correct |
2 |
Correct |
330 ms |
814884 KB |
Output is correct |
3 |
Correct |
380 ms |
814748 KB |
Output is correct |
4 |
Correct |
315 ms |
814820 KB |
Output is correct |
5 |
Correct |
308 ms |
814744 KB |
Output is correct |
6 |
Correct |
312 ms |
814780 KB |
Output is correct |
7 |
Correct |
340 ms |
814920 KB |
Output is correct |
8 |
Correct |
323 ms |
814828 KB |
Output is correct |
9 |
Correct |
324 ms |
814836 KB |
Output is correct |
10 |
Correct |
314 ms |
814796 KB |
Output is correct |
11 |
Correct |
320 ms |
815068 KB |
Output is correct |
12 |
Correct |
322 ms |
814760 KB |
Output is correct |
13 |
Correct |
316 ms |
814844 KB |
Output is correct |
14 |
Correct |
311 ms |
814760 KB |
Output is correct |
15 |
Correct |
312 ms |
814852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
307 ms |
814780 KB |
Output is correct |
2 |
Correct |
330 ms |
814884 KB |
Output is correct |
3 |
Correct |
380 ms |
814748 KB |
Output is correct |
4 |
Correct |
315 ms |
814820 KB |
Output is correct |
5 |
Correct |
308 ms |
814744 KB |
Output is correct |
6 |
Correct |
312 ms |
814780 KB |
Output is correct |
7 |
Correct |
340 ms |
814920 KB |
Output is correct |
8 |
Correct |
323 ms |
814828 KB |
Output is correct |
9 |
Correct |
324 ms |
814836 KB |
Output is correct |
10 |
Correct |
314 ms |
814796 KB |
Output is correct |
11 |
Correct |
320 ms |
815068 KB |
Output is correct |
12 |
Correct |
322 ms |
814760 KB |
Output is correct |
13 |
Correct |
316 ms |
814844 KB |
Output is correct |
14 |
Correct |
311 ms |
814760 KB |
Output is correct |
15 |
Correct |
312 ms |
814852 KB |
Output is correct |
16 |
Correct |
330 ms |
814744 KB |
Output is correct |
17 |
Correct |
319 ms |
814740 KB |
Output is correct |
18 |
Correct |
315 ms |
814796 KB |
Output is correct |
19 |
Correct |
311 ms |
814740 KB |
Output is correct |
20 |
Correct |
316 ms |
814836 KB |
Output is correct |
21 |
Correct |
360 ms |
814796 KB |
Output is correct |
22 |
Correct |
312 ms |
814764 KB |
Output is correct |
23 |
Correct |
327 ms |
814852 KB |
Output is correct |
24 |
Correct |
314 ms |
814772 KB |
Output is correct |
25 |
Correct |
325 ms |
814820 KB |
Output is correct |
26 |
Correct |
363 ms |
814788 KB |
Output is correct |
27 |
Correct |
314 ms |
814844 KB |
Output is correct |
28 |
Correct |
315 ms |
814832 KB |
Output is correct |
29 |
Correct |
328 ms |
814840 KB |
Output is correct |
30 |
Correct |
323 ms |
814820 KB |
Output is correct |
31 |
Correct |
317 ms |
814804 KB |
Output is correct |
32 |
Correct |
315 ms |
814864 KB |
Output is correct |
33 |
Correct |
313 ms |
814728 KB |
Output is correct |
34 |
Correct |
317 ms |
814796 KB |
Output is correct |
35 |
Correct |
321 ms |
814844 KB |
Output is correct |
36 |
Correct |
348 ms |
814796 KB |
Output is correct |
37 |
Correct |
321 ms |
814812 KB |
Output is correct |
38 |
Correct |
316 ms |
814796 KB |
Output is correct |
39 |
Correct |
354 ms |
814872 KB |
Output is correct |
40 |
Correct |
318 ms |
814788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
307 ms |
814780 KB |
Output is correct |
2 |
Correct |
330 ms |
814884 KB |
Output is correct |
3 |
Correct |
380 ms |
814748 KB |
Output is correct |
4 |
Correct |
315 ms |
814820 KB |
Output is correct |
5 |
Correct |
308 ms |
814744 KB |
Output is correct |
6 |
Correct |
312 ms |
814780 KB |
Output is correct |
7 |
Correct |
340 ms |
814920 KB |
Output is correct |
8 |
Correct |
323 ms |
814828 KB |
Output is correct |
9 |
Correct |
324 ms |
814836 KB |
Output is correct |
10 |
Correct |
314 ms |
814796 KB |
Output is correct |
11 |
Correct |
320 ms |
815068 KB |
Output is correct |
12 |
Correct |
322 ms |
814760 KB |
Output is correct |
13 |
Correct |
316 ms |
814844 KB |
Output is correct |
14 |
Correct |
311 ms |
814760 KB |
Output is correct |
15 |
Correct |
312 ms |
814852 KB |
Output is correct |
16 |
Correct |
330 ms |
814744 KB |
Output is correct |
17 |
Correct |
319 ms |
814740 KB |
Output is correct |
18 |
Correct |
315 ms |
814796 KB |
Output is correct |
19 |
Correct |
311 ms |
814740 KB |
Output is correct |
20 |
Correct |
316 ms |
814836 KB |
Output is correct |
21 |
Correct |
360 ms |
814796 KB |
Output is correct |
22 |
Correct |
312 ms |
814764 KB |
Output is correct |
23 |
Correct |
327 ms |
814852 KB |
Output is correct |
24 |
Correct |
314 ms |
814772 KB |
Output is correct |
25 |
Correct |
325 ms |
814820 KB |
Output is correct |
26 |
Correct |
363 ms |
814788 KB |
Output is correct |
27 |
Correct |
314 ms |
814844 KB |
Output is correct |
28 |
Correct |
315 ms |
814832 KB |
Output is correct |
29 |
Correct |
328 ms |
814840 KB |
Output is correct |
30 |
Correct |
323 ms |
814820 KB |
Output is correct |
31 |
Correct |
317 ms |
814804 KB |
Output is correct |
32 |
Correct |
315 ms |
814864 KB |
Output is correct |
33 |
Correct |
313 ms |
814728 KB |
Output is correct |
34 |
Correct |
317 ms |
814796 KB |
Output is correct |
35 |
Correct |
321 ms |
814844 KB |
Output is correct |
36 |
Correct |
348 ms |
814796 KB |
Output is correct |
37 |
Correct |
321 ms |
814812 KB |
Output is correct |
38 |
Correct |
316 ms |
814796 KB |
Output is correct |
39 |
Correct |
354 ms |
814872 KB |
Output is correct |
40 |
Correct |
318 ms |
814788 KB |
Output is correct |
41 |
Correct |
1 ms |
312 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
391 ms |
814812 KB |
Output is correct |
2 |
Correct |
306 ms |
814760 KB |
Output is correct |
3 |
Correct |
312 ms |
814816 KB |
Output is correct |
4 |
Correct |
318 ms |
814940 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 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 |
320 ms |
814808 KB |
Output is correct |
12 |
Correct |
1 ms |
256 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 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 |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
307 ms |
814780 KB |
Output is correct |
22 |
Correct |
330 ms |
814884 KB |
Output is correct |
23 |
Correct |
380 ms |
814748 KB |
Output is correct |
24 |
Correct |
315 ms |
814820 KB |
Output is correct |
25 |
Correct |
308 ms |
814744 KB |
Output is correct |
26 |
Correct |
312 ms |
814780 KB |
Output is correct |
27 |
Correct |
340 ms |
814920 KB |
Output is correct |
28 |
Correct |
323 ms |
814828 KB |
Output is correct |
29 |
Correct |
324 ms |
814836 KB |
Output is correct |
30 |
Correct |
314 ms |
814796 KB |
Output is correct |
31 |
Correct |
320 ms |
815068 KB |
Output is correct |
32 |
Correct |
322 ms |
814760 KB |
Output is correct |
33 |
Correct |
316 ms |
814844 KB |
Output is correct |
34 |
Correct |
311 ms |
814760 KB |
Output is correct |
35 |
Correct |
312 ms |
814852 KB |
Output is correct |
36 |
Correct |
330 ms |
814744 KB |
Output is correct |
37 |
Correct |
319 ms |
814740 KB |
Output is correct |
38 |
Correct |
315 ms |
814796 KB |
Output is correct |
39 |
Correct |
311 ms |
814740 KB |
Output is correct |
40 |
Correct |
316 ms |
814836 KB |
Output is correct |
41 |
Correct |
360 ms |
814796 KB |
Output is correct |
42 |
Correct |
312 ms |
814764 KB |
Output is correct |
43 |
Correct |
327 ms |
814852 KB |
Output is correct |
44 |
Correct |
314 ms |
814772 KB |
Output is correct |
45 |
Correct |
325 ms |
814820 KB |
Output is correct |
46 |
Correct |
363 ms |
814788 KB |
Output is correct |
47 |
Correct |
314 ms |
814844 KB |
Output is correct |
48 |
Correct |
315 ms |
814832 KB |
Output is correct |
49 |
Correct |
328 ms |
814840 KB |
Output is correct |
50 |
Correct |
323 ms |
814820 KB |
Output is correct |
51 |
Correct |
317 ms |
814804 KB |
Output is correct |
52 |
Correct |
315 ms |
814864 KB |
Output is correct |
53 |
Correct |
313 ms |
814728 KB |
Output is correct |
54 |
Correct |
317 ms |
814796 KB |
Output is correct |
55 |
Correct |
321 ms |
814844 KB |
Output is correct |
56 |
Correct |
348 ms |
814796 KB |
Output is correct |
57 |
Correct |
321 ms |
814812 KB |
Output is correct |
58 |
Correct |
316 ms |
814796 KB |
Output is correct |
59 |
Correct |
354 ms |
814872 KB |
Output is correct |
60 |
Correct |
318 ms |
814788 KB |
Output is correct |
61 |
Correct |
1 ms |
312 KB |
Output is correct |
62 |
Correct |
1 ms |
212 KB |
Output is correct |
63 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
64 |
Halted |
0 ms |
0 KB |
- |