#include <bits/stdc++.h>
typedef long long ll;
struct Gym {
ll L, X;
};
bool operator<(const Gym &a, const Gym &b) {
if (a.X != b.X) {
return a.X < b.X;
}
return a.L < b.L;
}
int main() {
ll n;
std::cin >> n;
std::vector<Gym> a(n);
for (ll i = 0; i < n; ++ i) {
std::cin >> a[i].X;
}
for (ll i = 0; i < n; ++ i) {
std::cin >> a[i].L;
}
std::sort(a.begin(), a.end(), [](const Gym &i, const Gym &j) {
return std::min(i.L, j.L - i.X) > std::min(j.L, i.L - j.X);
});
std::multiset<Gym> dp;
ll level = 0;
for (ll i = 0; i < n; ++ i) {
if (dp.empty() || level <= a[i].L) {
dp.insert(a[i]);
level += a[i].X;
} else if (level - dp.rbegin()->X <= a[i].L && dp.rbegin()->X > a[i].X) {
level -= dp.rbegin()->X;
dp.erase(--dp.end());
dp.insert(a[i]);
level += a[i].X;
}
}
std::cout << dp.size() << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
287 ms |
17492 KB |
Output is correct |
2 |
Correct |
288 ms |
17488 KB |
Output is correct |
3 |
Correct |
283 ms |
17492 KB |
Output is correct |
4 |
Correct |
287 ms |
17492 KB |
Output is correct |
5 |
Correct |
284 ms |
17748 KB |
Output is correct |
6 |
Correct |
269 ms |
17748 KB |
Output is correct |
7 |
Correct |
262 ms |
16180 KB |
Output is correct |
8 |
Correct |
267 ms |
17492 KB |
Output is correct |
9 |
Correct |
268 ms |
17748 KB |
Output is correct |
10 |
Correct |
267 ms |
18260 KB |
Output is correct |
11 |
Correct |
282 ms |
29520 KB |
Output is correct |
12 |
Correct |
282 ms |
32176 KB |
Output is correct |
13 |
Correct |
288 ms |
31312 KB |
Output is correct |
14 |
Correct |
283 ms |
32048 KB |
Output is correct |
15 |
Correct |
289 ms |
33496 KB |
Output is correct |
16 |
Correct |
260 ms |
20392 KB |
Output is correct |
17 |
Correct |
274 ms |
21332 KB |
Output is correct |
18 |
Correct |
262 ms |
21840 KB |
Output is correct |
19 |
Correct |
257 ms |
19536 KB |
Output is correct |
20 |
Correct |
258 ms |
18092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
4 ms |
600 KB |
Output is correct |
22 |
Correct |
3 ms |
604 KB |
Output is correct |
23 |
Correct |
3 ms |
604 KB |
Output is correct |
24 |
Correct |
3 ms |
604 KB |
Output is correct |
25 |
Correct |
3 ms |
604 KB |
Output is correct |
26 |
Correct |
3 ms |
600 KB |
Output is correct |
27 |
Correct |
4 ms |
604 KB |
Output is correct |
28 |
Correct |
3 ms |
600 KB |
Output is correct |
29 |
Correct |
4 ms |
604 KB |
Output is correct |
30 |
Correct |
3 ms |
604 KB |
Output is correct |
31 |
Correct |
4 ms |
604 KB |
Output is correct |
32 |
Correct |
3 ms |
604 KB |
Output is correct |
33 |
Correct |
3 ms |
604 KB |
Output is correct |
34 |
Correct |
4 ms |
604 KB |
Output is correct |
35 |
Correct |
3 ms |
604 KB |
Output is correct |
36 |
Correct |
3 ms |
596 KB |
Output is correct |
37 |
Correct |
3 ms |
604 KB |
Output is correct |
38 |
Correct |
3 ms |
596 KB |
Output is correct |
39 |
Correct |
4 ms |
604 KB |
Output is correct |
40 |
Correct |
3 ms |
604 KB |
Output is correct |
41 |
Correct |
3 ms |
600 KB |
Output is correct |
42 |
Correct |
3 ms |
600 KB |
Output is correct |
43 |
Correct |
3 ms |
600 KB |
Output is correct |
44 |
Correct |
4 ms |
604 KB |
Output is correct |
45 |
Correct |
4 ms |
604 KB |
Output is correct |
46 |
Correct |
5 ms |
856 KB |
Output is correct |
47 |
Correct |
4 ms |
860 KB |
Output is correct |
48 |
Correct |
3 ms |
860 KB |
Output is correct |
49 |
Correct |
3 ms |
860 KB |
Output is correct |
50 |
Correct |
3 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
287 ms |
17492 KB |
Output is correct |
22 |
Correct |
288 ms |
17488 KB |
Output is correct |
23 |
Correct |
283 ms |
17492 KB |
Output is correct |
24 |
Correct |
287 ms |
17492 KB |
Output is correct |
25 |
Correct |
284 ms |
17748 KB |
Output is correct |
26 |
Correct |
269 ms |
17748 KB |
Output is correct |
27 |
Correct |
262 ms |
16180 KB |
Output is correct |
28 |
Correct |
267 ms |
17492 KB |
Output is correct |
29 |
Correct |
268 ms |
17748 KB |
Output is correct |
30 |
Correct |
267 ms |
18260 KB |
Output is correct |
31 |
Correct |
282 ms |
29520 KB |
Output is correct |
32 |
Correct |
282 ms |
32176 KB |
Output is correct |
33 |
Correct |
288 ms |
31312 KB |
Output is correct |
34 |
Correct |
283 ms |
32048 KB |
Output is correct |
35 |
Correct |
289 ms |
33496 KB |
Output is correct |
36 |
Correct |
260 ms |
20392 KB |
Output is correct |
37 |
Correct |
274 ms |
21332 KB |
Output is correct |
38 |
Correct |
262 ms |
21840 KB |
Output is correct |
39 |
Correct |
257 ms |
19536 KB |
Output is correct |
40 |
Correct |
258 ms |
18092 KB |
Output is correct |
41 |
Correct |
4 ms |
600 KB |
Output is correct |
42 |
Correct |
3 ms |
604 KB |
Output is correct |
43 |
Correct |
3 ms |
604 KB |
Output is correct |
44 |
Correct |
3 ms |
604 KB |
Output is correct |
45 |
Correct |
3 ms |
604 KB |
Output is correct |
46 |
Correct |
3 ms |
600 KB |
Output is correct |
47 |
Correct |
4 ms |
604 KB |
Output is correct |
48 |
Correct |
3 ms |
600 KB |
Output is correct |
49 |
Correct |
4 ms |
604 KB |
Output is correct |
50 |
Correct |
3 ms |
604 KB |
Output is correct |
51 |
Correct |
4 ms |
604 KB |
Output is correct |
52 |
Correct |
3 ms |
604 KB |
Output is correct |
53 |
Correct |
3 ms |
604 KB |
Output is correct |
54 |
Correct |
4 ms |
604 KB |
Output is correct |
55 |
Correct |
3 ms |
604 KB |
Output is correct |
56 |
Correct |
3 ms |
596 KB |
Output is correct |
57 |
Correct |
3 ms |
604 KB |
Output is correct |
58 |
Correct |
3 ms |
596 KB |
Output is correct |
59 |
Correct |
4 ms |
604 KB |
Output is correct |
60 |
Correct |
3 ms |
604 KB |
Output is correct |
61 |
Correct |
3 ms |
600 KB |
Output is correct |
62 |
Correct |
3 ms |
600 KB |
Output is correct |
63 |
Correct |
3 ms |
600 KB |
Output is correct |
64 |
Correct |
4 ms |
604 KB |
Output is correct |
65 |
Correct |
4 ms |
604 KB |
Output is correct |
66 |
Correct |
5 ms |
856 KB |
Output is correct |
67 |
Correct |
4 ms |
860 KB |
Output is correct |
68 |
Correct |
3 ms |
860 KB |
Output is correct |
69 |
Correct |
3 ms |
860 KB |
Output is correct |
70 |
Correct |
3 ms |
860 KB |
Output is correct |
71 |
Correct |
0 ms |
348 KB |
Output is correct |
72 |
Correct |
0 ms |
348 KB |
Output is correct |
73 |
Correct |
281 ms |
17980 KB |
Output is correct |
74 |
Correct |
276 ms |
17744 KB |
Output is correct |
75 |
Correct |
289 ms |
17960 KB |
Output is correct |
76 |
Correct |
292 ms |
17968 KB |
Output is correct |
77 |
Correct |
287 ms |
18004 KB |
Output is correct |
78 |
Correct |
304 ms |
22060 KB |
Output is correct |
79 |
Correct |
301 ms |
21840 KB |
Output is correct |
80 |
Correct |
297 ms |
21840 KB |
Output is correct |
81 |
Correct |
309 ms |
22096 KB |
Output is correct |
82 |
Correct |
300 ms |
21844 KB |
Output is correct |
83 |
Correct |
350 ms |
29116 KB |
Output is correct |
84 |
Correct |
327 ms |
29008 KB |
Output is correct |
85 |
Correct |
321 ms |
29236 KB |
Output is correct |
86 |
Correct |
318 ms |
29236 KB |
Output is correct |
87 |
Correct |
328 ms |
29268 KB |
Output is correct |
88 |
Correct |
357 ms |
36528 KB |
Output is correct |
89 |
Correct |
368 ms |
36536 KB |
Output is correct |
90 |
Correct |
373 ms |
36436 KB |
Output is correct |
91 |
Correct |
393 ms |
36536 KB |
Output is correct |
92 |
Correct |
389 ms |
36412 KB |
Output is correct |
93 |
Correct |
429 ms |
40712 KB |
Output is correct |
94 |
Correct |
413 ms |
40784 KB |
Output is correct |
95 |
Correct |
431 ms |
40784 KB |
Output is correct |
96 |
Correct |
445 ms |
40788 KB |
Output is correct |
97 |
Correct |
417 ms |
40788 KB |
Output is correct |
98 |
Correct |
286 ms |
18732 KB |
Output is correct |
99 |
Correct |
296 ms |
18608 KB |
Output is correct |
100 |
Correct |
285 ms |
18776 KB |
Output is correct |
101 |
Correct |
445 ms |
46512 KB |
Output is correct |
102 |
Correct |
502 ms |
46384 KB |
Output is correct |