// while (clock()<=69*CLOCKS_PER_SEC)
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("O3")
// #pragma GCC target ("avx2")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x) \
sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
{
sim > struct rge {
c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef XOX
~debug()
{
cerr << endl;
}
eni(!=) cerr << boolalpha << i;
ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
ris << "" << d.first << " --> " << d.second << "";
}
sim dor(rge<c> d)
{
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c &)
{
ris;
}
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#ifdef XOX
#warning Times may differ!!!
#endif
#define endl '\n'
#define pb emplace_back
#define vt vector
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int nax = 1000 * 1007, mod = 1e9 + 7;
int main()
{
cin.tie(0)->sync_with_stdio(0);
int n, k;
cin >> n >> k;
vt<pii> wek(n);
for (auto &[a, b] : wek) {
cin >> a >> b;
if (b == -1) b = mod;
}
sort(all(wek), [](const pii &a, const pii &b) {
return a.second < b.second;
});
typedef double T;
auto solve_for = [&](int m) {
vt<vt<T>> dp(n + 1, vt<T>(k - m + 1, mod));
dp[0][0] = 0.;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= k - m; j++) {
int bylo = i - j;
if (j < k - m) dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + (T)wek[i].first / (m + 1));
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + (bylo >= m ? 0. : (T)wek[i].second / (bylo + 1)));
}
}
return dp[n][k - m];
};
int a = 0, b = k;
while (b - a >= 3) {
int p_1 = a + (b - a) / 3;
int p_2 = b - (b - a) / 3;
assert(p_1 != p_2);
if (solve_for(p_1) <= solve_for(p_2)) b = p_2;
else a = p_1;
}
T ans = mod;
for (int i = 0; i <= k; i++) {
debug() << imie(i) imie(solve_for(i));
}
debug() << imie(a) imie(b);
for (int i = a; i <= b; i++) {
ans = min(ans, solve_for(i));
}
cout << fixed << setprecision(15) << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
6 ms |
540 KB |
Output is correct |
6 |
Correct |
27 ms |
1292 KB |
Output is correct |
7 |
Correct |
107 ms |
1512 KB |
Output is correct |
8 |
Correct |
225 ms |
2000 KB |
Output is correct |
9 |
Correct |
399 ms |
2584 KB |
Output is correct |
10 |
Correct |
177 ms |
1876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
6 ms |
540 KB |
Output is correct |
6 |
Correct |
27 ms |
1292 KB |
Output is correct |
7 |
Correct |
107 ms |
1512 KB |
Output is correct |
8 |
Correct |
225 ms |
2000 KB |
Output is correct |
9 |
Correct |
399 ms |
2584 KB |
Output is correct |
10 |
Correct |
177 ms |
1876 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
29 ms |
944 KB |
Output is correct |
13 |
Correct |
33 ms |
964 KB |
Output is correct |
14 |
Correct |
33 ms |
1292 KB |
Output is correct |
15 |
Correct |
157 ms |
1740 KB |
Output is correct |
16 |
Correct |
175 ms |
1776 KB |
Output is correct |
17 |
Correct |
178 ms |
1696 KB |
Output is correct |
18 |
Correct |
329 ms |
2340 KB |
Output is correct |
19 |
Correct |
353 ms |
2292 KB |
Output is correct |
20 |
Correct |
386 ms |
2352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 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 |
0 ms |
320 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
324 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
0 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 |
316 KB |
Output is correct |
34 |
Correct |
1 ms |
328 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 |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 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 |
0 ms |
320 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
324 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
0 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 |
316 KB |
Output is correct |
34 |
Correct |
1 ms |
328 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 |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
2 ms |
340 KB |
Output is correct |
48 |
Correct |
2 ms |
340 KB |
Output is correct |
49 |
Correct |
2 ms |
340 KB |
Output is correct |
50 |
Correct |
2 ms |
340 KB |
Output is correct |
51 |
Correct |
3 ms |
468 KB |
Output is correct |
52 |
Correct |
3 ms |
468 KB |
Output is correct |
53 |
Correct |
2 ms |
340 KB |
Output is correct |
54 |
Correct |
2 ms |
324 KB |
Output is correct |
55 |
Correct |
2 ms |
340 KB |
Output is correct |
56 |
Correct |
2 ms |
316 KB |
Output is correct |
57 |
Correct |
2 ms |
320 KB |
Output is correct |
58 |
Correct |
2 ms |
340 KB |
Output is correct |
59 |
Correct |
2 ms |
340 KB |
Output is correct |
60 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
359 ms |
2416 KB |
Output is correct |
2 |
Correct |
353 ms |
2408 KB |
Output is correct |
3 |
Correct |
347 ms |
2320 KB |
Output is correct |
4 |
Correct |
347 ms |
2384 KB |
Output is correct |
5 |
Correct |
335 ms |
2356 KB |
Output is correct |
6 |
Correct |
357 ms |
2288 KB |
Output is correct |
7 |
Correct |
337 ms |
2364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
6 ms |
540 KB |
Output is correct |
6 |
Correct |
27 ms |
1292 KB |
Output is correct |
7 |
Correct |
107 ms |
1512 KB |
Output is correct |
8 |
Correct |
225 ms |
2000 KB |
Output is correct |
9 |
Correct |
399 ms |
2584 KB |
Output is correct |
10 |
Correct |
177 ms |
1876 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
29 ms |
944 KB |
Output is correct |
13 |
Correct |
33 ms |
964 KB |
Output is correct |
14 |
Correct |
33 ms |
1292 KB |
Output is correct |
15 |
Correct |
157 ms |
1740 KB |
Output is correct |
16 |
Correct |
175 ms |
1776 KB |
Output is correct |
17 |
Correct |
178 ms |
1696 KB |
Output is correct |
18 |
Correct |
329 ms |
2340 KB |
Output is correct |
19 |
Correct |
353 ms |
2292 KB |
Output is correct |
20 |
Correct |
386 ms |
2352 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
324 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
320 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
1 ms |
324 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
0 ms |
212 KB |
Output is correct |
52 |
Correct |
0 ms |
212 KB |
Output is correct |
53 |
Correct |
1 ms |
316 KB |
Output is correct |
54 |
Correct |
1 ms |
328 KB |
Output is correct |
55 |
Correct |
1 ms |
212 KB |
Output is correct |
56 |
Correct |
1 ms |
212 KB |
Output is correct |
57 |
Correct |
1 ms |
212 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
212 KB |
Output is correct |
60 |
Correct |
0 ms |
212 KB |
Output is correct |
61 |
Correct |
1 ms |
212 KB |
Output is correct |
62 |
Correct |
1 ms |
340 KB |
Output is correct |
63 |
Correct |
1 ms |
340 KB |
Output is correct |
64 |
Correct |
1 ms |
340 KB |
Output is correct |
65 |
Correct |
1 ms |
340 KB |
Output is correct |
66 |
Correct |
1 ms |
340 KB |
Output is correct |
67 |
Correct |
2 ms |
340 KB |
Output is correct |
68 |
Correct |
2 ms |
340 KB |
Output is correct |
69 |
Correct |
2 ms |
340 KB |
Output is correct |
70 |
Correct |
2 ms |
340 KB |
Output is correct |
71 |
Correct |
3 ms |
468 KB |
Output is correct |
72 |
Correct |
3 ms |
468 KB |
Output is correct |
73 |
Correct |
2 ms |
340 KB |
Output is correct |
74 |
Correct |
2 ms |
324 KB |
Output is correct |
75 |
Correct |
2 ms |
340 KB |
Output is correct |
76 |
Correct |
2 ms |
316 KB |
Output is correct |
77 |
Correct |
2 ms |
320 KB |
Output is correct |
78 |
Correct |
2 ms |
340 KB |
Output is correct |
79 |
Correct |
2 ms |
340 KB |
Output is correct |
80 |
Correct |
2 ms |
340 KB |
Output is correct |
81 |
Correct |
359 ms |
2416 KB |
Output is correct |
82 |
Correct |
353 ms |
2408 KB |
Output is correct |
83 |
Correct |
347 ms |
2320 KB |
Output is correct |
84 |
Correct |
347 ms |
2384 KB |
Output is correct |
85 |
Correct |
335 ms |
2356 KB |
Output is correct |
86 |
Correct |
357 ms |
2288 KB |
Output is correct |
87 |
Correct |
337 ms |
2364 KB |
Output is correct |
88 |
Correct |
10 ms |
532 KB |
Output is correct |
89 |
Correct |
4 ms |
528 KB |
Output is correct |
90 |
Correct |
25 ms |
888 KB |
Output is correct |
91 |
Correct |
21 ms |
860 KB |
Output is correct |
92 |
Correct |
88 ms |
1308 KB |
Output is correct |
93 |
Correct |
87 ms |
1376 KB |
Output is correct |
94 |
Correct |
202 ms |
1804 KB |
Output is correct |
95 |
Correct |
187 ms |
1884 KB |
Output is correct |
96 |
Correct |
282 ms |
2212 KB |
Output is correct |
97 |
Correct |
276 ms |
2184 KB |
Output is correct |
98 |
Correct |
234 ms |
1780 KB |
Output is correct |
99 |
Correct |
186 ms |
1792 KB |
Output is correct |
100 |
Correct |
184 ms |
1836 KB |
Output is correct |
101 |
Correct |
166 ms |
1720 KB |
Output is correct |
102 |
Correct |
194 ms |
1792 KB |
Output is correct |
103 |
Correct |
166 ms |
1776 KB |
Output is correct |
104 |
Correct |
166 ms |
1804 KB |
Output is correct |
105 |
Correct |
181 ms |
1964 KB |
Output is correct |