import java.util.Arrays; import java.util.Scanner; public class Yuki1 { public static void main(String[] argas) { Scanner scan = new Scanner(System.in); // 箱の幅 int box = scan.nextInt(); //int box = 16; // ブロックの数 int blockCount = scan.nextInt(); //int blockCount = 3; int num = scan.nextInt(); int blockWidth[] = new int [num]; //int blockWidth[] = {4,5,1,1}; for (int i = 0; i <= num; i++) { blockWidth[i] = scan.nextInt(); } Arrays.sort(blockWidth); for(int i = 0; i< 3; i++){ System.out.println(blockWidth[i]); } int boxWidthAll = 0; int boxWidthAllCount = 0; while(box>boxWidthAll && blockCount>boxWidthAllCount){ boxWidthAll +=blockWidth[boxWidthAllCount]; if(box>boxWidthAll) { boxWidthAllCount++; } } System.out.println(boxWidthAllCount); } }