#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 5e5+5, S = 10, inf = LLONG_MAX;
int n, x[N], l[N];
pair<int, int> s[N];
map<int, int> dp[N];
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x[i];
}
bool eq = 1;
for (int i = 0; i < n; i++) {
cin >> l[i];
if (l[i] != l[0]) eq = 0;
}
for (int i = 0; i < n; i++) {
s[i] = make_pair(x[i]+l[i], i);
}
sort(s, s+n);
if (eq) {
int ans = 0;
int lvl = 0;
for (int i = 0; i < n; i++) {
int idx = s[i].second;
if (lvl <= l[idx]) {
ans++;
lvl += x[idx];
}
}
cout << ans << "\n";
}
else {
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
int cnt = 0;
auto it = dp[i].end();
while (it != dp[i].begin()) {
if (cnt++ > S) break;
--it;
int j = it->first;
int k = it->second;
auto it2 = dp[i+1].find(j);
if (it2 == dp[i+1].end()) dp[i+1][j] = k;
else it2->second = min(it2->second, k);
if (l[s[i].second] >= k) {
it2 = dp[i+1].find(j+1);
if (it2 == dp[i+1].end()) dp[i+1][j+1] = k + x[s[i].second];
else it2->second = min(it2->second, k + x[s[i].second]);
}
}
dp[i].clear();
}
for (int i = n; i >= 0; i--) {
if (dp[n].find(i) != dp[n].end()) {
cout << i << "\n";
break;
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
29276 KB |
Output is correct |
2 |
Correct |
5 ms |
29276 KB |
Output is correct |
3 |
Correct |
6 ms |
29276 KB |
Output is correct |
4 |
Correct |
6 ms |
29272 KB |
Output is correct |
5 |
Correct |
6 ms |
29276 KB |
Output is correct |
6 |
Correct |
7 ms |
29276 KB |
Output is correct |
7 |
Correct |
5 ms |
29272 KB |
Output is correct |
8 |
Correct |
6 ms |
29276 KB |
Output is correct |
9 |
Correct |
5 ms |
29276 KB |
Output is correct |
10 |
Correct |
5 ms |
29272 KB |
Output is correct |
11 |
Correct |
5 ms |
29276 KB |
Output is correct |
12 |
Correct |
6 ms |
29276 KB |
Output is correct |
13 |
Correct |
6 ms |
29312 KB |
Output is correct |
14 |
Correct |
5 ms |
29276 KB |
Output is correct |
15 |
Correct |
6 ms |
29276 KB |
Output is correct |
16 |
Correct |
5 ms |
29276 KB |
Output is correct |
17 |
Correct |
5 ms |
29320 KB |
Output is correct |
18 |
Correct |
7 ms |
29276 KB |
Output is correct |
19 |
Correct |
7 ms |
29532 KB |
Output is correct |
20 |
Correct |
5 ms |
29276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
39508 KB |
Output is correct |
2 |
Correct |
124 ms |
39572 KB |
Output is correct |
3 |
Correct |
115 ms |
39508 KB |
Output is correct |
4 |
Correct |
114 ms |
39760 KB |
Output is correct |
5 |
Correct |
117 ms |
39508 KB |
Output is correct |
6 |
Correct |
110 ms |
39508 KB |
Output is correct |
7 |
Correct |
108 ms |
39340 KB |
Output is correct |
8 |
Correct |
113 ms |
39552 KB |
Output is correct |
9 |
Correct |
111 ms |
39556 KB |
Output is correct |
10 |
Correct |
109 ms |
39504 KB |
Output is correct |
11 |
Correct |
113 ms |
39548 KB |
Output is correct |
12 |
Correct |
113 ms |
39508 KB |
Output is correct |
13 |
Correct |
122 ms |
39508 KB |
Output is correct |
14 |
Correct |
115 ms |
39508 KB |
Output is correct |
15 |
Correct |
114 ms |
39508 KB |
Output is correct |
16 |
Correct |
112 ms |
39572 KB |
Output is correct |
17 |
Correct |
121 ms |
39736 KB |
Output is correct |
18 |
Correct |
113 ms |
39504 KB |
Output is correct |
19 |
Correct |
112 ms |
39508 KB |
Output is correct |
20 |
Correct |
112 ms |
39508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
29276 KB |
Output is correct |
2 |
Correct |
5 ms |
29276 KB |
Output is correct |
3 |
Correct |
6 ms |
29276 KB |
Output is correct |
4 |
Correct |
6 ms |
29272 KB |
Output is correct |
5 |
Correct |
6 ms |
29276 KB |
Output is correct |
6 |
Correct |
7 ms |
29276 KB |
Output is correct |
7 |
Correct |
5 ms |
29272 KB |
Output is correct |
8 |
Correct |
6 ms |
29276 KB |
Output is correct |
9 |
Correct |
5 ms |
29276 KB |
Output is correct |
10 |
Correct |
5 ms |
29272 KB |
Output is correct |
11 |
Correct |
5 ms |
29276 KB |
Output is correct |
12 |
Correct |
6 ms |
29276 KB |
Output is correct |
13 |
Correct |
6 ms |
29312 KB |
Output is correct |
14 |
Correct |
5 ms |
29276 KB |
Output is correct |
15 |
Correct |
6 ms |
29276 KB |
Output is correct |
16 |
Correct |
5 ms |
29276 KB |
Output is correct |
17 |
Correct |
5 ms |
29320 KB |
Output is correct |
18 |
Correct |
7 ms |
29276 KB |
Output is correct |
19 |
Correct |
7 ms |
29532 KB |
Output is correct |
20 |
Correct |
5 ms |
29276 KB |
Output is correct |
21 |
Correct |
11 ms |
29528 KB |
Output is correct |
22 |
Correct |
10 ms |
29528 KB |
Output is correct |
23 |
Correct |
9 ms |
29276 KB |
Output is correct |
24 |
Correct |
9 ms |
29276 KB |
Output is correct |
25 |
Correct |
9 ms |
29272 KB |
Output is correct |
26 |
Correct |
9 ms |
29276 KB |
Output is correct |
27 |
Correct |
9 ms |
29312 KB |
Output is correct |
28 |
Correct |
9 ms |
29276 KB |
Output is correct |
29 |
Correct |
9 ms |
29272 KB |
Output is correct |
30 |
Correct |
9 ms |
29276 KB |
Output is correct |
31 |
Correct |
9 ms |
29276 KB |
Output is correct |
32 |
Correct |
9 ms |
29276 KB |
Output is correct |
33 |
Correct |
10 ms |
29276 KB |
Output is correct |
34 |
Correct |
10 ms |
29276 KB |
Output is correct |
35 |
Correct |
9 ms |
29276 KB |
Output is correct |
36 |
Correct |
9 ms |
29276 KB |
Output is correct |
37 |
Correct |
10 ms |
29276 KB |
Output is correct |
38 |
Correct |
9 ms |
29276 KB |
Output is correct |
39 |
Correct |
10 ms |
29368 KB |
Output is correct |
40 |
Correct |
9 ms |
29272 KB |
Output is correct |
41 |
Correct |
9 ms |
29272 KB |
Output is correct |
42 |
Correct |
9 ms |
29276 KB |
Output is correct |
43 |
Correct |
9 ms |
29276 KB |
Output is correct |
44 |
Correct |
9 ms |
29276 KB |
Output is correct |
45 |
Correct |
10 ms |
29276 KB |
Output is correct |
46 |
Correct |
9 ms |
29276 KB |
Output is correct |
47 |
Correct |
9 ms |
29276 KB |
Output is correct |
48 |
Correct |
9 ms |
29360 KB |
Output is correct |
49 |
Correct |
9 ms |
29276 KB |
Output is correct |
50 |
Correct |
9 ms |
29356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
29276 KB |
Output is correct |
2 |
Correct |
5 ms |
29276 KB |
Output is correct |
3 |
Correct |
6 ms |
29276 KB |
Output is correct |
4 |
Correct |
6 ms |
29272 KB |
Output is correct |
5 |
Correct |
6 ms |
29276 KB |
Output is correct |
6 |
Correct |
7 ms |
29276 KB |
Output is correct |
7 |
Correct |
5 ms |
29272 KB |
Output is correct |
8 |
Correct |
6 ms |
29276 KB |
Output is correct |
9 |
Correct |
5 ms |
29276 KB |
Output is correct |
10 |
Correct |
5 ms |
29272 KB |
Output is correct |
11 |
Correct |
5 ms |
29276 KB |
Output is correct |
12 |
Correct |
6 ms |
29276 KB |
Output is correct |
13 |
Correct |
6 ms |
29312 KB |
Output is correct |
14 |
Correct |
5 ms |
29276 KB |
Output is correct |
15 |
Correct |
6 ms |
29276 KB |
Output is correct |
16 |
Correct |
5 ms |
29276 KB |
Output is correct |
17 |
Correct |
5 ms |
29320 KB |
Output is correct |
18 |
Correct |
7 ms |
29276 KB |
Output is correct |
19 |
Correct |
7 ms |
29532 KB |
Output is correct |
20 |
Correct |
5 ms |
29276 KB |
Output is correct |
21 |
Correct |
113 ms |
39508 KB |
Output is correct |
22 |
Correct |
124 ms |
39572 KB |
Output is correct |
23 |
Correct |
115 ms |
39508 KB |
Output is correct |
24 |
Correct |
114 ms |
39760 KB |
Output is correct |
25 |
Correct |
117 ms |
39508 KB |
Output is correct |
26 |
Correct |
110 ms |
39508 KB |
Output is correct |
27 |
Correct |
108 ms |
39340 KB |
Output is correct |
28 |
Correct |
113 ms |
39552 KB |
Output is correct |
29 |
Correct |
111 ms |
39556 KB |
Output is correct |
30 |
Correct |
109 ms |
39504 KB |
Output is correct |
31 |
Correct |
113 ms |
39548 KB |
Output is correct |
32 |
Correct |
113 ms |
39508 KB |
Output is correct |
33 |
Correct |
122 ms |
39508 KB |
Output is correct |
34 |
Correct |
115 ms |
39508 KB |
Output is correct |
35 |
Correct |
114 ms |
39508 KB |
Output is correct |
36 |
Correct |
112 ms |
39572 KB |
Output is correct |
37 |
Correct |
121 ms |
39736 KB |
Output is correct |
38 |
Correct |
113 ms |
39504 KB |
Output is correct |
39 |
Correct |
112 ms |
39508 KB |
Output is correct |
40 |
Correct |
112 ms |
39508 KB |
Output is correct |
41 |
Correct |
11 ms |
29528 KB |
Output is correct |
42 |
Correct |
10 ms |
29528 KB |
Output is correct |
43 |
Correct |
9 ms |
29276 KB |
Output is correct |
44 |
Correct |
9 ms |
29276 KB |
Output is correct |
45 |
Correct |
9 ms |
29272 KB |
Output is correct |
46 |
Correct |
9 ms |
29276 KB |
Output is correct |
47 |
Correct |
9 ms |
29312 KB |
Output is correct |
48 |
Correct |
9 ms |
29276 KB |
Output is correct |
49 |
Correct |
9 ms |
29272 KB |
Output is correct |
50 |
Correct |
9 ms |
29276 KB |
Output is correct |
51 |
Correct |
9 ms |
29276 KB |
Output is correct |
52 |
Correct |
9 ms |
29276 KB |
Output is correct |
53 |
Correct |
10 ms |
29276 KB |
Output is correct |
54 |
Correct |
10 ms |
29276 KB |
Output is correct |
55 |
Correct |
9 ms |
29276 KB |
Output is correct |
56 |
Correct |
9 ms |
29276 KB |
Output is correct |
57 |
Correct |
10 ms |
29276 KB |
Output is correct |
58 |
Correct |
9 ms |
29276 KB |
Output is correct |
59 |
Correct |
10 ms |
29368 KB |
Output is correct |
60 |
Correct |
9 ms |
29272 KB |
Output is correct |
61 |
Correct |
9 ms |
29272 KB |
Output is correct |
62 |
Correct |
9 ms |
29276 KB |
Output is correct |
63 |
Correct |
9 ms |
29276 KB |
Output is correct |
64 |
Correct |
9 ms |
29276 KB |
Output is correct |
65 |
Correct |
10 ms |
29276 KB |
Output is correct |
66 |
Correct |
9 ms |
29276 KB |
Output is correct |
67 |
Correct |
9 ms |
29276 KB |
Output is correct |
68 |
Correct |
9 ms |
29360 KB |
Output is correct |
69 |
Correct |
9 ms |
29276 KB |
Output is correct |
70 |
Correct |
9 ms |
29356 KB |
Output is correct |
71 |
Correct |
6 ms |
29272 KB |
Output is correct |
72 |
Correct |
5 ms |
29276 KB |
Output is correct |
73 |
Correct |
318 ms |
39572 KB |
Output is correct |
74 |
Correct |
318 ms |
39392 KB |
Output is correct |
75 |
Correct |
317 ms |
39452 KB |
Output is correct |
76 |
Correct |
319 ms |
39764 KB |
Output is correct |
77 |
Correct |
320 ms |
39824 KB |
Output is correct |
78 |
Correct |
347 ms |
39572 KB |
Output is correct |
79 |
Correct |
342 ms |
39504 KB |
Output is correct |
80 |
Correct |
332 ms |
39568 KB |
Output is correct |
81 |
Correct |
329 ms |
39596 KB |
Output is correct |
82 |
Correct |
330 ms |
39568 KB |
Output is correct |
83 |
Correct |
348 ms |
39568 KB |
Output is correct |
84 |
Correct |
349 ms |
39760 KB |
Output is correct |
85 |
Correct |
356 ms |
39504 KB |
Output is correct |
86 |
Correct |
350 ms |
39576 KB |
Output is correct |
87 |
Correct |
344 ms |
39560 KB |
Output is correct |
88 |
Correct |
364 ms |
39760 KB |
Output is correct |
89 |
Correct |
356 ms |
39508 KB |
Output is correct |
90 |
Correct |
361 ms |
39596 KB |
Output is correct |
91 |
Correct |
353 ms |
39504 KB |
Output is correct |
92 |
Correct |
367 ms |
39764 KB |
Output is correct |
93 |
Correct |
354 ms |
39560 KB |
Output is correct |
94 |
Correct |
377 ms |
39568 KB |
Output is correct |
95 |
Correct |
365 ms |
39524 KB |
Output is correct |
96 |
Correct |
367 ms |
39336 KB |
Output is correct |
97 |
Correct |
356 ms |
39568 KB |
Output is correct |
98 |
Correct |
322 ms |
39508 KB |
Output is correct |
99 |
Correct |
322 ms |
40252 KB |
Output is correct |
100 |
Correct |
335 ms |
39508 KB |
Output is correct |
101 |
Correct |
382 ms |
39600 KB |
Output is correct |
102 |
Correct |
359 ms |
39572 KB |
Output is correct |