import java.util.Arrays; import java.util.HashSet; import java.util.LinkedList; import java.util.Scanner; import java.util.Set; public class Main { public static int answer = -1; public static void dfs(final int deep, final int N, int[] items, final int M, int[] boxes, boolean[] used, int count){ //System.out.println(deep + " " + count); if(deep >= N){ //System.out.println(Arrays.toString(used)); if(answer < 0 || answer > count){ answer = count; } return; }else if(answer >= 0 && count >= answer){ return; } for(int i = 0; i < M; i++){ if(boxes[i] < items[deep]){ continue; } final boolean first_use = !used[i]; if(first_use){ used[i] = true; } boxes[i] -= items[deep]; dfs(deep + 1, N, items, M, boxes, used, count + (first_use ? 1 : 0)); boxes[i] += items[deep]; if(first_use){ used[i] = false; } } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); int[] items = new int[N]; for(int i = 0; i < N; i++){ items[i] = -sc.nextInt(); } Arrays.sort(items); for(int i = 0; i < N; i++){ items[i] = -items[i]; } final int M = sc.nextInt(); int[] boxes = new int[M]; for(int i = 0; i < M; i++){ boxes[i] = sc.nextInt(); } dfs(0, N, items, M, boxes, new boolean[M], 0); System.out.println(answer); } }