#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
int N;
cin >> N;
vector<int> X;
for (int i = 0; i < N; i++) {
int Xi;
cin >> Xi;
X.push_back(Xi);
}
vector<int> L;
for (int i = 0; i < N; i++) {
int Li;
cin >> Li;
L.push_back(Li);
}
if (N > 10) {
int ans = 0;
sort(X.begin(),X.end());
ll currLevel = 0;
ll cap = L.back();
vector<int>::iterator p = X.begin();
while ((currLevel <= cap)&&(p!=X.end())) {
ans++;
currLevel += *p;
p++;
}
cout << ans << endl;
} else {
int ans = 0;
vector<int> perm;
for (int i = 0; i < N; i++) {
perm.push_back(i);
}
do {
int currAns = 0;
ll currLevel = 0;
for(auto p = perm.begin(); p != perm.end(); p++) {
if (currLevel > L[*p]) {
break;
} else {
currAns++;
currLevel += X[*p];
}
}
ans = max(currAns,ans);
} while(next_permutation(perm.begin(),perm.end()));
cout << ans << endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
21 ms |
296 KB |
Output is correct |
4 |
Correct |
19 ms |
212 KB |
Output is correct |
5 |
Correct |
18 ms |
212 KB |
Output is correct |
6 |
Correct |
18 ms |
296 KB |
Output is correct |
7 |
Correct |
2 ms |
212 KB |
Output is correct |
8 |
Correct |
24 ms |
212 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 |
23 ms |
296 KB |
Output is correct |
14 |
Correct |
20 ms |
212 KB |
Output is correct |
15 |
Correct |
19 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
212 KB |
Output is correct |
17 |
Correct |
3 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
31 ms |
212 KB |
Output is correct |
20 |
Correct |
31 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
388 ms |
5460 KB |
Output is correct |
2 |
Correct |
370 ms |
5420 KB |
Output is correct |
3 |
Correct |
377 ms |
5460 KB |
Output is correct |
4 |
Correct |
373 ms |
5376 KB |
Output is correct |
5 |
Correct |
389 ms |
5392 KB |
Output is correct |
6 |
Correct |
370 ms |
5452 KB |
Output is correct |
7 |
Correct |
328 ms |
5432 KB |
Output is correct |
8 |
Correct |
349 ms |
5408 KB |
Output is correct |
9 |
Correct |
406 ms |
5368 KB |
Output is correct |
10 |
Correct |
346 ms |
5392 KB |
Output is correct |
11 |
Correct |
322 ms |
5392 KB |
Output is correct |
12 |
Correct |
326 ms |
5400 KB |
Output is correct |
13 |
Correct |
313 ms |
5304 KB |
Output is correct |
14 |
Correct |
326 ms |
5408 KB |
Output is correct |
15 |
Correct |
309 ms |
5544 KB |
Output is correct |
16 |
Correct |
339 ms |
5376 KB |
Output is correct |
17 |
Correct |
377 ms |
5424 KB |
Output is correct |
18 |
Correct |
349 ms |
5316 KB |
Output is correct |
19 |
Correct |
353 ms |
5468 KB |
Output is correct |
20 |
Correct |
338 ms |
5368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
21 ms |
296 KB |
Output is correct |
4 |
Correct |
19 ms |
212 KB |
Output is correct |
5 |
Correct |
18 ms |
212 KB |
Output is correct |
6 |
Correct |
18 ms |
296 KB |
Output is correct |
7 |
Correct |
2 ms |
212 KB |
Output is correct |
8 |
Correct |
24 ms |
212 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 |
23 ms |
296 KB |
Output is correct |
14 |
Correct |
20 ms |
212 KB |
Output is correct |
15 |
Correct |
19 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
212 KB |
Output is correct |
17 |
Correct |
3 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
31 ms |
212 KB |
Output is correct |
20 |
Correct |
31 ms |
212 KB |
Output is correct |
21 |
Incorrect |
5 ms |
352 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
21 ms |
296 KB |
Output is correct |
4 |
Correct |
19 ms |
212 KB |
Output is correct |
5 |
Correct |
18 ms |
212 KB |
Output is correct |
6 |
Correct |
18 ms |
296 KB |
Output is correct |
7 |
Correct |
2 ms |
212 KB |
Output is correct |
8 |
Correct |
24 ms |
212 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 |
23 ms |
296 KB |
Output is correct |
14 |
Correct |
20 ms |
212 KB |
Output is correct |
15 |
Correct |
19 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
212 KB |
Output is correct |
17 |
Correct |
3 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
31 ms |
212 KB |
Output is correct |
20 |
Correct |
31 ms |
212 KB |
Output is correct |
21 |
Correct |
388 ms |
5460 KB |
Output is correct |
22 |
Correct |
370 ms |
5420 KB |
Output is correct |
23 |
Correct |
377 ms |
5460 KB |
Output is correct |
24 |
Correct |
373 ms |
5376 KB |
Output is correct |
25 |
Correct |
389 ms |
5392 KB |
Output is correct |
26 |
Correct |
370 ms |
5452 KB |
Output is correct |
27 |
Correct |
328 ms |
5432 KB |
Output is correct |
28 |
Correct |
349 ms |
5408 KB |
Output is correct |
29 |
Correct |
406 ms |
5368 KB |
Output is correct |
30 |
Correct |
346 ms |
5392 KB |
Output is correct |
31 |
Correct |
322 ms |
5392 KB |
Output is correct |
32 |
Correct |
326 ms |
5400 KB |
Output is correct |
33 |
Correct |
313 ms |
5304 KB |
Output is correct |
34 |
Correct |
326 ms |
5408 KB |
Output is correct |
35 |
Correct |
309 ms |
5544 KB |
Output is correct |
36 |
Correct |
339 ms |
5376 KB |
Output is correct |
37 |
Correct |
377 ms |
5424 KB |
Output is correct |
38 |
Correct |
349 ms |
5316 KB |
Output is correct |
39 |
Correct |
353 ms |
5468 KB |
Output is correct |
40 |
Correct |
338 ms |
5368 KB |
Output is correct |
41 |
Incorrect |
5 ms |
352 KB |
Output isn't correct |
42 |
Halted |
0 ms |
0 KB |
- |