#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]);
}
}
dp[i].clear();
}
for (int i = n; i >= 0; i--) {
if (dp[n].find(i) != dp[n].end()) {
cout << i << "\n";
break;
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
29276 KB |
Output is correct |
2 |
Correct |
5 ms |
29372 KB |
Output is correct |
3 |
Correct |
6 ms |
29276 KB |
Output is correct |
4 |
Correct |
5 ms |
29276 KB |
Output is correct |
5 |
Correct |
6 ms |
29276 KB |
Output is correct |
6 |
Correct |
6 ms |
29312 KB |
Output is correct |
7 |
Correct |
6 ms |
29280 KB |
Output is correct |
8 |
Correct |
6 ms |
29276 KB |
Output is correct |
9 |
Correct |
6 ms |
29276 KB |
Output is correct |
10 |
Correct |
6 ms |
29368 KB |
Output is correct |
11 |
Correct |
6 ms |
29352 KB |
Output is correct |
12 |
Correct |
6 ms |
29276 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 |
29300 KB |
Output is correct |
16 |
Correct |
6 ms |
29476 KB |
Output is correct |
17 |
Correct |
6 ms |
29272 KB |
Output is correct |
18 |
Correct |
6 ms |
29272 KB |
Output is correct |
19 |
Correct |
5 ms |
29276 KB |
Output is correct |
20 |
Correct |
6 ms |
29276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
116 ms |
47952 KB |
Output is correct |
2 |
Correct |
116 ms |
47912 KB |
Output is correct |
3 |
Correct |
123 ms |
48292 KB |
Output is correct |
4 |
Correct |
116 ms |
47956 KB |
Output is correct |
5 |
Correct |
117 ms |
48208 KB |
Output is correct |
6 |
Correct |
116 ms |
47240 KB |
Output is correct |
7 |
Correct |
114 ms |
47064 KB |
Output is correct |
8 |
Correct |
114 ms |
47256 KB |
Output is correct |
9 |
Correct |
114 ms |
47184 KB |
Output is correct |
10 |
Correct |
116 ms |
47256 KB |
Output is correct |
11 |
Correct |
116 ms |
46420 KB |
Output is correct |
12 |
Correct |
116 ms |
46420 KB |
Output is correct |
13 |
Correct |
116 ms |
46548 KB |
Output is correct |
14 |
Correct |
117 ms |
46412 KB |
Output is correct |
15 |
Correct |
117 ms |
46480 KB |
Output is correct |
16 |
Correct |
116 ms |
46712 KB |
Output is correct |
17 |
Correct |
139 ms |
46736 KB |
Output is correct |
18 |
Correct |
116 ms |
46744 KB |
Output is correct |
19 |
Correct |
126 ms |
46672 KB |
Output is correct |
20 |
Correct |
117 ms |
46672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
29276 KB |
Output is correct |
2 |
Correct |
5 ms |
29372 KB |
Output is correct |
3 |
Correct |
6 ms |
29276 KB |
Output is correct |
4 |
Correct |
5 ms |
29276 KB |
Output is correct |
5 |
Correct |
6 ms |
29276 KB |
Output is correct |
6 |
Correct |
6 ms |
29312 KB |
Output is correct |
7 |
Correct |
6 ms |
29280 KB |
Output is correct |
8 |
Correct |
6 ms |
29276 KB |
Output is correct |
9 |
Correct |
6 ms |
29276 KB |
Output is correct |
10 |
Correct |
6 ms |
29368 KB |
Output is correct |
11 |
Correct |
6 ms |
29352 KB |
Output is correct |
12 |
Correct |
6 ms |
29276 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 |
29300 KB |
Output is correct |
16 |
Correct |
6 ms |
29476 KB |
Output is correct |
17 |
Correct |
6 ms |
29272 KB |
Output is correct |
18 |
Correct |
6 ms |
29272 KB |
Output is correct |
19 |
Correct |
5 ms |
29276 KB |
Output is correct |
20 |
Correct |
6 ms |
29276 KB |
Output is correct |
21 |
Correct |
30 ms |
29272 KB |
Output is correct |
22 |
Correct |
30 ms |
29272 KB |
Output is correct |
23 |
Correct |
30 ms |
29276 KB |
Output is correct |
24 |
Correct |
30 ms |
29476 KB |
Output is correct |
25 |
Correct |
30 ms |
29276 KB |
Output is correct |
26 |
Correct |
31 ms |
29276 KB |
Output is correct |
27 |
Correct |
32 ms |
29276 KB |
Output is correct |
28 |
Correct |
31 ms |
29276 KB |
Output is correct |
29 |
Correct |
32 ms |
29444 KB |
Output is correct |
30 |
Correct |
31 ms |
29272 KB |
Output is correct |
31 |
Correct |
32 ms |
29272 KB |
Output is correct |
32 |
Correct |
32 ms |
29276 KB |
Output is correct |
33 |
Correct |
32 ms |
29272 KB |
Output is correct |
34 |
Correct |
37 ms |
29276 KB |
Output is correct |
35 |
Correct |
32 ms |
29272 KB |
Output is correct |
36 |
Correct |
34 ms |
29276 KB |
Output is correct |
37 |
Correct |
32 ms |
29460 KB |
Output is correct |
38 |
Correct |
32 ms |
29436 KB |
Output is correct |
39 |
Correct |
33 ms |
29272 KB |
Output is correct |
40 |
Correct |
32 ms |
29272 KB |
Output is correct |
41 |
Correct |
34 ms |
29272 KB |
Output is correct |
42 |
Correct |
34 ms |
29308 KB |
Output is correct |
43 |
Correct |
33 ms |
29276 KB |
Output is correct |
44 |
Correct |
33 ms |
29276 KB |
Output is correct |
45 |
Correct |
33 ms |
29276 KB |
Output is correct |
46 |
Correct |
34 ms |
29276 KB |
Output is correct |
47 |
Correct |
37 ms |
29272 KB |
Output is correct |
48 |
Correct |
34 ms |
29436 KB |
Output is correct |
49 |
Correct |
33 ms |
29276 KB |
Output is correct |
50 |
Correct |
34 ms |
29428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
29276 KB |
Output is correct |
2 |
Correct |
5 ms |
29372 KB |
Output is correct |
3 |
Correct |
6 ms |
29276 KB |
Output is correct |
4 |
Correct |
5 ms |
29276 KB |
Output is correct |
5 |
Correct |
6 ms |
29276 KB |
Output is correct |
6 |
Correct |
6 ms |
29312 KB |
Output is correct |
7 |
Correct |
6 ms |
29280 KB |
Output is correct |
8 |
Correct |
6 ms |
29276 KB |
Output is correct |
9 |
Correct |
6 ms |
29276 KB |
Output is correct |
10 |
Correct |
6 ms |
29368 KB |
Output is correct |
11 |
Correct |
6 ms |
29352 KB |
Output is correct |
12 |
Correct |
6 ms |
29276 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 |
29300 KB |
Output is correct |
16 |
Correct |
6 ms |
29476 KB |
Output is correct |
17 |
Correct |
6 ms |
29272 KB |
Output is correct |
18 |
Correct |
6 ms |
29272 KB |
Output is correct |
19 |
Correct |
5 ms |
29276 KB |
Output is correct |
20 |
Correct |
6 ms |
29276 KB |
Output is correct |
21 |
Correct |
116 ms |
47952 KB |
Output is correct |
22 |
Correct |
116 ms |
47912 KB |
Output is correct |
23 |
Correct |
123 ms |
48292 KB |
Output is correct |
24 |
Correct |
116 ms |
47956 KB |
Output is correct |
25 |
Correct |
117 ms |
48208 KB |
Output is correct |
26 |
Correct |
116 ms |
47240 KB |
Output is correct |
27 |
Correct |
114 ms |
47064 KB |
Output is correct |
28 |
Correct |
114 ms |
47256 KB |
Output is correct |
29 |
Correct |
114 ms |
47184 KB |
Output is correct |
30 |
Correct |
116 ms |
47256 KB |
Output is correct |
31 |
Correct |
116 ms |
46420 KB |
Output is correct |
32 |
Correct |
116 ms |
46420 KB |
Output is correct |
33 |
Correct |
116 ms |
46548 KB |
Output is correct |
34 |
Correct |
117 ms |
46412 KB |
Output is correct |
35 |
Correct |
117 ms |
46480 KB |
Output is correct |
36 |
Correct |
116 ms |
46712 KB |
Output is correct |
37 |
Correct |
139 ms |
46736 KB |
Output is correct |
38 |
Correct |
116 ms |
46744 KB |
Output is correct |
39 |
Correct |
126 ms |
46672 KB |
Output is correct |
40 |
Correct |
117 ms |
46672 KB |
Output is correct |
41 |
Correct |
30 ms |
29272 KB |
Output is correct |
42 |
Correct |
30 ms |
29272 KB |
Output is correct |
43 |
Correct |
30 ms |
29276 KB |
Output is correct |
44 |
Correct |
30 ms |
29476 KB |
Output is correct |
45 |
Correct |
30 ms |
29276 KB |
Output is correct |
46 |
Correct |
31 ms |
29276 KB |
Output is correct |
47 |
Correct |
32 ms |
29276 KB |
Output is correct |
48 |
Correct |
31 ms |
29276 KB |
Output is correct |
49 |
Correct |
32 ms |
29444 KB |
Output is correct |
50 |
Correct |
31 ms |
29272 KB |
Output is correct |
51 |
Correct |
32 ms |
29272 KB |
Output is correct |
52 |
Correct |
32 ms |
29276 KB |
Output is correct |
53 |
Correct |
32 ms |
29272 KB |
Output is correct |
54 |
Correct |
37 ms |
29276 KB |
Output is correct |
55 |
Correct |
32 ms |
29272 KB |
Output is correct |
56 |
Correct |
34 ms |
29276 KB |
Output is correct |
57 |
Correct |
32 ms |
29460 KB |
Output is correct |
58 |
Correct |
32 ms |
29436 KB |
Output is correct |
59 |
Correct |
33 ms |
29272 KB |
Output is correct |
60 |
Correct |
32 ms |
29272 KB |
Output is correct |
61 |
Correct |
34 ms |
29272 KB |
Output is correct |
62 |
Correct |
34 ms |
29308 KB |
Output is correct |
63 |
Correct |
33 ms |
29276 KB |
Output is correct |
64 |
Correct |
33 ms |
29276 KB |
Output is correct |
65 |
Correct |
33 ms |
29276 KB |
Output is correct |
66 |
Correct |
34 ms |
29276 KB |
Output is correct |
67 |
Correct |
37 ms |
29272 KB |
Output is correct |
68 |
Correct |
34 ms |
29436 KB |
Output is correct |
69 |
Correct |
33 ms |
29276 KB |
Output is correct |
70 |
Correct |
34 ms |
29428 KB |
Output is correct |
71 |
Correct |
6 ms |
29276 KB |
Output is correct |
72 |
Correct |
5 ms |
29276 KB |
Output is correct |
73 |
Execution timed out |
2025 ms |
48892 KB |
Time limit exceeded |
74 |
Halted |
0 ms |
0 KB |
- |