-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1092
88 lines (65 loc) · 1.48 KB
/
1092
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import java.util.*;
public class Main {
public static int get_max(int[] cnt) {
int max=0;
for(int i=0; i<cnt.length; i++) {
if(cnt[i]>max)
max=cnt[i];
}
return max;
}
public static int[] sub_box(int[] box, int state) {
int[] temp = new int[box.length-1];
for(int i=0; i<box.length-1; i++) {
if(i<state)
temp[i] = box[i];
else
temp[i] = box[i+1];
}
return temp;
}
public static int check(int[] crane, int[] box) {
int result = -1;
int[] cnt = new int[crane.length];
if(crane[crane.length-1]<box[box.length-1])
return result;
while(box.length!=0) {
int index = crane.length-1;
for(int i=box.length-1; i>=0; i--) {
if(crane[index]>=box[i]) {
//체크
// System.out.println(index+1 + "번째 크레인에 "+box[i]+"박스");
box = sub_box(box,i);
cnt[index]++;
if(index>=1)
index--;
else {
//체크
// System.out.println("index가 0이라 빠져나옴");
break;
}
}
}
}
result = get_max(cnt);
return result;
}
public static void main(String[] args) {
int n,m;
int[] crane;
int[] box;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
crane = new int[n];
for(int i=0; i<n; i++)
crane[i] = sc.nextInt();
m = sc.nextInt();
box = new int[m];
for(int i=0; i<m; i++)
box[i] = sc.nextInt();
Arrays.sort(crane);
Arrays.sort(box);
System.out.println(check(crane,box));
sc.close();
}
}