#include <bits/stdc++.h>
using namespace std;
#define lln long long
void solve() {
lln n; cin >> n;
lln gain[n], cap[n];
for (lln i=0;i<n;i++) cin >> gain[i];
for (lln i=0;i<n;i++) cin >> cap[i];
lln ans = 0;
if (n <= 10) {
vector<lln> cur;
for (lln i=0;i<n;i++) cur.push_back(i);
do {
lln level = 0, badges = 0;
for (auto index : cur) {
if (level <= cap[index]) {
level += gain[index];
badges++;
}
}
ans = max(ans, badges);
} while (next_permutation(cur.begin(),cur.end()));
}
else { // if cap is constant for all gyms
vector<pair<lln,lln> > gyms; //gain, cap
for (lln i=0;i<n;i++) gyms.push_back(make_pair(gain[i], cap[i]));
sort(gyms.begin(),gyms.end());
lln level = 0, badges = 0;
for (lln i=0;i<n;i++) {
if (level <= get<1>(gyms[i])) {
level += get<0>(gyms[i]);
badges++;
}
}
ans = max(ans, badges);
}
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
while (t--) solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
212 KB |
Output is correct |
3 |
Correct |
73 ms |
292 KB |
Output is correct |
4 |
Correct |
71 ms |
296 KB |
Output is correct |
5 |
Correct |
70 ms |
212 KB |
Output is correct |
6 |
Correct |
67 ms |
212 KB |
Output is correct |
7 |
Correct |
6 ms |
212 KB |
Output is correct |
8 |
Correct |
67 ms |
300 KB |
Output is correct |
9 |
Correct |
1 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 |
87 ms |
212 KB |
Output is correct |
14 |
Correct |
67 ms |
212 KB |
Output is correct |
15 |
Correct |
64 ms |
296 KB |
Output is correct |
16 |
Correct |
7 ms |
312 KB |
Output is correct |
17 |
Correct |
8 ms |
212 KB |
Output is correct |
18 |
Correct |
2 ms |
212 KB |
Output is correct |
19 |
Correct |
97 ms |
292 KB |
Output is correct |
20 |
Correct |
92 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
187 ms |
16448 KB |
Output is correct |
2 |
Correct |
145 ms |
16816 KB |
Output is correct |
3 |
Correct |
149 ms |
16816 KB |
Output is correct |
4 |
Correct |
162 ms |
16832 KB |
Output is correct |
5 |
Correct |
153 ms |
16780 KB |
Output is correct |
6 |
Correct |
147 ms |
16824 KB |
Output is correct |
7 |
Correct |
147 ms |
16816 KB |
Output is correct |
8 |
Correct |
136 ms |
16836 KB |
Output is correct |
9 |
Correct |
147 ms |
16832 KB |
Output is correct |
10 |
Correct |
144 ms |
16852 KB |
Output is correct |
11 |
Correct |
134 ms |
16808 KB |
Output is correct |
12 |
Correct |
125 ms |
16692 KB |
Output is correct |
13 |
Correct |
136 ms |
16672 KB |
Output is correct |
14 |
Correct |
128 ms |
16704 KB |
Output is correct |
15 |
Correct |
126 ms |
16704 KB |
Output is correct |
16 |
Correct |
137 ms |
16620 KB |
Output is correct |
17 |
Correct |
138 ms |
16624 KB |
Output is correct |
18 |
Correct |
140 ms |
16688 KB |
Output is correct |
19 |
Correct |
140 ms |
16680 KB |
Output is correct |
20 |
Correct |
170 ms |
16684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
212 KB |
Output is correct |
3 |
Correct |
73 ms |
292 KB |
Output is correct |
4 |
Correct |
71 ms |
296 KB |
Output is correct |
5 |
Correct |
70 ms |
212 KB |
Output is correct |
6 |
Correct |
67 ms |
212 KB |
Output is correct |
7 |
Correct |
6 ms |
212 KB |
Output is correct |
8 |
Correct |
67 ms |
300 KB |
Output is correct |
9 |
Correct |
1 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 |
87 ms |
212 KB |
Output is correct |
14 |
Correct |
67 ms |
212 KB |
Output is correct |
15 |
Correct |
64 ms |
296 KB |
Output is correct |
16 |
Correct |
7 ms |
312 KB |
Output is correct |
17 |
Correct |
8 ms |
212 KB |
Output is correct |
18 |
Correct |
2 ms |
212 KB |
Output is correct |
19 |
Correct |
97 ms |
292 KB |
Output is correct |
20 |
Correct |
92 ms |
212 KB |
Output is correct |
21 |
Incorrect |
2 ms |
520 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
212 KB |
Output is correct |
3 |
Correct |
73 ms |
292 KB |
Output is correct |
4 |
Correct |
71 ms |
296 KB |
Output is correct |
5 |
Correct |
70 ms |
212 KB |
Output is correct |
6 |
Correct |
67 ms |
212 KB |
Output is correct |
7 |
Correct |
6 ms |
212 KB |
Output is correct |
8 |
Correct |
67 ms |
300 KB |
Output is correct |
9 |
Correct |
1 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 |
87 ms |
212 KB |
Output is correct |
14 |
Correct |
67 ms |
212 KB |
Output is correct |
15 |
Correct |
64 ms |
296 KB |
Output is correct |
16 |
Correct |
7 ms |
312 KB |
Output is correct |
17 |
Correct |
8 ms |
212 KB |
Output is correct |
18 |
Correct |
2 ms |
212 KB |
Output is correct |
19 |
Correct |
97 ms |
292 KB |
Output is correct |
20 |
Correct |
92 ms |
212 KB |
Output is correct |
21 |
Correct |
187 ms |
16448 KB |
Output is correct |
22 |
Correct |
145 ms |
16816 KB |
Output is correct |
23 |
Correct |
149 ms |
16816 KB |
Output is correct |
24 |
Correct |
162 ms |
16832 KB |
Output is correct |
25 |
Correct |
153 ms |
16780 KB |
Output is correct |
26 |
Correct |
147 ms |
16824 KB |
Output is correct |
27 |
Correct |
147 ms |
16816 KB |
Output is correct |
28 |
Correct |
136 ms |
16836 KB |
Output is correct |
29 |
Correct |
147 ms |
16832 KB |
Output is correct |
30 |
Correct |
144 ms |
16852 KB |
Output is correct |
31 |
Correct |
134 ms |
16808 KB |
Output is correct |
32 |
Correct |
125 ms |
16692 KB |
Output is correct |
33 |
Correct |
136 ms |
16672 KB |
Output is correct |
34 |
Correct |
128 ms |
16704 KB |
Output is correct |
35 |
Correct |
126 ms |
16704 KB |
Output is correct |
36 |
Correct |
137 ms |
16620 KB |
Output is correct |
37 |
Correct |
138 ms |
16624 KB |
Output is correct |
38 |
Correct |
140 ms |
16688 KB |
Output is correct |
39 |
Correct |
140 ms |
16680 KB |
Output is correct |
40 |
Correct |
170 ms |
16684 KB |
Output is correct |
41 |
Incorrect |
2 ms |
520 KB |
Output isn't correct |
42 |
Halted |
0 ms |
0 KB |
- |