#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 5e5+5, S = 100, 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]);
}
}
}
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 |
6 ms |
29276 KB |
Output is correct |
2 |
Correct |
6 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 |
6 ms |
29324 KB |
Output is correct |
7 |
Correct |
6 ms |
29272 KB |
Output is correct |
8 |
Correct |
7 ms |
29272 KB |
Output is correct |
9 |
Correct |
6 ms |
29276 KB |
Output is correct |
10 |
Correct |
6 ms |
29276 KB |
Output is correct |
11 |
Correct |
6 ms |
29276 KB |
Output is correct |
12 |
Correct |
6 ms |
29348 KB |
Output is correct |
13 |
Correct |
6 ms |
29276 KB |
Output is correct |
14 |
Correct |
6 ms |
29276 KB |
Output is correct |
15 |
Correct |
6 ms |
29276 KB |
Output is correct |
16 |
Correct |
6 ms |
29276 KB |
Output is correct |
17 |
Correct |
6 ms |
29364 KB |
Output is correct |
18 |
Correct |
6 ms |
29276 KB |
Output is correct |
19 |
Correct |
6 ms |
29272 KB |
Output is correct |
20 |
Correct |
6 ms |
29276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
115 ms |
39512 KB |
Output is correct |
2 |
Correct |
120 ms |
39508 KB |
Output is correct |
3 |
Correct |
116 ms |
39504 KB |
Output is correct |
4 |
Correct |
116 ms |
39508 KB |
Output is correct |
5 |
Correct |
114 ms |
39556 KB |
Output is correct |
6 |
Correct |
113 ms |
39508 KB |
Output is correct |
7 |
Correct |
112 ms |
39504 KB |
Output is correct |
8 |
Correct |
116 ms |
39504 KB |
Output is correct |
9 |
Correct |
119 ms |
39508 KB |
Output is correct |
10 |
Correct |
111 ms |
39484 KB |
Output is correct |
11 |
Correct |
117 ms |
39540 KB |
Output is correct |
12 |
Correct |
115 ms |
39568 KB |
Output is correct |
13 |
Correct |
121 ms |
39380 KB |
Output is correct |
14 |
Correct |
117 ms |
39332 KB |
Output is correct |
15 |
Correct |
119 ms |
39556 KB |
Output is correct |
16 |
Correct |
116 ms |
39508 KB |
Output is correct |
17 |
Correct |
119 ms |
39760 KB |
Output is correct |
18 |
Correct |
120 ms |
39508 KB |
Output is correct |
19 |
Correct |
131 ms |
39560 KB |
Output is correct |
20 |
Correct |
129 ms |
39504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
29276 KB |
Output is correct |
2 |
Correct |
6 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 |
6 ms |
29324 KB |
Output is correct |
7 |
Correct |
6 ms |
29272 KB |
Output is correct |
8 |
Correct |
7 ms |
29272 KB |
Output is correct |
9 |
Correct |
6 ms |
29276 KB |
Output is correct |
10 |
Correct |
6 ms |
29276 KB |
Output is correct |
11 |
Correct |
6 ms |
29276 KB |
Output is correct |
12 |
Correct |
6 ms |
29348 KB |
Output is correct |
13 |
Correct |
6 ms |
29276 KB |
Output is correct |
14 |
Correct |
6 ms |
29276 KB |
Output is correct |
15 |
Correct |
6 ms |
29276 KB |
Output is correct |
16 |
Correct |
6 ms |
29276 KB |
Output is correct |
17 |
Correct |
6 ms |
29364 KB |
Output is correct |
18 |
Correct |
6 ms |
29276 KB |
Output is correct |
19 |
Correct |
6 ms |
29272 KB |
Output is correct |
20 |
Correct |
6 ms |
29276 KB |
Output is correct |
21 |
Correct |
53 ms |
57680 KB |
Output is correct |
22 |
Correct |
55 ms |
58008 KB |
Output is correct |
23 |
Correct |
53 ms |
56864 KB |
Output is correct |
24 |
Correct |
53 ms |
57168 KB |
Output is correct |
25 |
Correct |
60 ms |
57420 KB |
Output is correct |
26 |
Correct |
59 ms |
59208 KB |
Output is correct |
27 |
Correct |
56 ms |
59732 KB |
Output is correct |
28 |
Correct |
56 ms |
59192 KB |
Output is correct |
29 |
Correct |
57 ms |
59612 KB |
Output is correct |
30 |
Correct |
57 ms |
59728 KB |
Output is correct |
31 |
Correct |
59 ms |
60244 KB |
Output is correct |
32 |
Correct |
58 ms |
59732 KB |
Output is correct |
33 |
Correct |
57 ms |
59988 KB |
Output is correct |
34 |
Correct |
59 ms |
60244 KB |
Output is correct |
35 |
Correct |
58 ms |
60172 KB |
Output is correct |
36 |
Correct |
63 ms |
60324 KB |
Output is correct |
37 |
Correct |
70 ms |
59988 KB |
Output is correct |
38 |
Correct |
58 ms |
59988 KB |
Output is correct |
39 |
Correct |
59 ms |
60420 KB |
Output is correct |
40 |
Correct |
61 ms |
59988 KB |
Output is correct |
41 |
Correct |
59 ms |
60496 KB |
Output is correct |
42 |
Correct |
61 ms |
60244 KB |
Output is correct |
43 |
Correct |
60 ms |
60316 KB |
Output is correct |
44 |
Correct |
59 ms |
60500 KB |
Output is correct |
45 |
Correct |
59 ms |
60232 KB |
Output is correct |
46 |
Correct |
60 ms |
60764 KB |
Output is correct |
47 |
Correct |
59 ms |
60496 KB |
Output is correct |
48 |
Correct |
60 ms |
60392 KB |
Output is correct |
49 |
Correct |
59 ms |
60244 KB |
Output is correct |
50 |
Correct |
59 ms |
60632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
29276 KB |
Output is correct |
2 |
Correct |
6 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 |
6 ms |
29324 KB |
Output is correct |
7 |
Correct |
6 ms |
29272 KB |
Output is correct |
8 |
Correct |
7 ms |
29272 KB |
Output is correct |
9 |
Correct |
6 ms |
29276 KB |
Output is correct |
10 |
Correct |
6 ms |
29276 KB |
Output is correct |
11 |
Correct |
6 ms |
29276 KB |
Output is correct |
12 |
Correct |
6 ms |
29348 KB |
Output is correct |
13 |
Correct |
6 ms |
29276 KB |
Output is correct |
14 |
Correct |
6 ms |
29276 KB |
Output is correct |
15 |
Correct |
6 ms |
29276 KB |
Output is correct |
16 |
Correct |
6 ms |
29276 KB |
Output is correct |
17 |
Correct |
6 ms |
29364 KB |
Output is correct |
18 |
Correct |
6 ms |
29276 KB |
Output is correct |
19 |
Correct |
6 ms |
29272 KB |
Output is correct |
20 |
Correct |
6 ms |
29276 KB |
Output is correct |
21 |
Correct |
115 ms |
39512 KB |
Output is correct |
22 |
Correct |
120 ms |
39508 KB |
Output is correct |
23 |
Correct |
116 ms |
39504 KB |
Output is correct |
24 |
Correct |
116 ms |
39508 KB |
Output is correct |
25 |
Correct |
114 ms |
39556 KB |
Output is correct |
26 |
Correct |
113 ms |
39508 KB |
Output is correct |
27 |
Correct |
112 ms |
39504 KB |
Output is correct |
28 |
Correct |
116 ms |
39504 KB |
Output is correct |
29 |
Correct |
119 ms |
39508 KB |
Output is correct |
30 |
Correct |
111 ms |
39484 KB |
Output is correct |
31 |
Correct |
117 ms |
39540 KB |
Output is correct |
32 |
Correct |
115 ms |
39568 KB |
Output is correct |
33 |
Correct |
121 ms |
39380 KB |
Output is correct |
34 |
Correct |
117 ms |
39332 KB |
Output is correct |
35 |
Correct |
119 ms |
39556 KB |
Output is correct |
36 |
Correct |
116 ms |
39508 KB |
Output is correct |
37 |
Correct |
119 ms |
39760 KB |
Output is correct |
38 |
Correct |
120 ms |
39508 KB |
Output is correct |
39 |
Correct |
131 ms |
39560 KB |
Output is correct |
40 |
Correct |
129 ms |
39504 KB |
Output is correct |
41 |
Correct |
53 ms |
57680 KB |
Output is correct |
42 |
Correct |
55 ms |
58008 KB |
Output is correct |
43 |
Correct |
53 ms |
56864 KB |
Output is correct |
44 |
Correct |
53 ms |
57168 KB |
Output is correct |
45 |
Correct |
60 ms |
57420 KB |
Output is correct |
46 |
Correct |
59 ms |
59208 KB |
Output is correct |
47 |
Correct |
56 ms |
59732 KB |
Output is correct |
48 |
Correct |
56 ms |
59192 KB |
Output is correct |
49 |
Correct |
57 ms |
59612 KB |
Output is correct |
50 |
Correct |
57 ms |
59728 KB |
Output is correct |
51 |
Correct |
59 ms |
60244 KB |
Output is correct |
52 |
Correct |
58 ms |
59732 KB |
Output is correct |
53 |
Correct |
57 ms |
59988 KB |
Output is correct |
54 |
Correct |
59 ms |
60244 KB |
Output is correct |
55 |
Correct |
58 ms |
60172 KB |
Output is correct |
56 |
Correct |
63 ms |
60324 KB |
Output is correct |
57 |
Correct |
70 ms |
59988 KB |
Output is correct |
58 |
Correct |
58 ms |
59988 KB |
Output is correct |
59 |
Correct |
59 ms |
60420 KB |
Output is correct |
60 |
Correct |
61 ms |
59988 KB |
Output is correct |
61 |
Correct |
59 ms |
60496 KB |
Output is correct |
62 |
Correct |
61 ms |
60244 KB |
Output is correct |
63 |
Correct |
60 ms |
60316 KB |
Output is correct |
64 |
Correct |
59 ms |
60500 KB |
Output is correct |
65 |
Correct |
59 ms |
60232 KB |
Output is correct |
66 |
Correct |
60 ms |
60764 KB |
Output is correct |
67 |
Correct |
59 ms |
60496 KB |
Output is correct |
68 |
Correct |
60 ms |
60392 KB |
Output is correct |
69 |
Correct |
59 ms |
60244 KB |
Output is correct |
70 |
Correct |
59 ms |
60632 KB |
Output is correct |
71 |
Correct |
6 ms |
29276 KB |
Output is correct |
72 |
Correct |
6 ms |
29360 KB |
Output is correct |
73 |
Runtime error |
1460 ms |
1048576 KB |
Execution killed with signal 9 |
74 |
Halted |
0 ms |
0 KB |
- |