結果
問題 | No.50 おもちゃ箱 |
ユーザー | yun_app |
提出日時 | 2016-05-13 16:12:11 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,192 bytes |
コンパイル時間 | 3,013 ms |
コンパイル使用メモリ | 90,864 KB |
実行使用メモリ | 51,176 KB |
最終ジャッジ日時 | 2024-04-15 15:30:08 |
合計ジャッジ時間 | 6,677 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 67 ms
50,636 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | AC | 66 ms
50,616 KB |
testcase_04 | AC | 66 ms
50,892 KB |
testcase_05 | AC | 67 ms
50,732 KB |
testcase_06 | AC | 68 ms
50,340 KB |
testcase_07 | AC | 69 ms
50,760 KB |
testcase_08 | AC | 68 ms
50,704 KB |
testcase_09 | AC | 68 ms
50,700 KB |
testcase_10 | AC | 68 ms
50,560 KB |
testcase_11 | WA | - |
testcase_12 | AC | 66 ms
50,672 KB |
testcase_13 | AC | 67 ms
50,732 KB |
testcase_14 | AC | 66 ms
50,740 KB |
testcase_15 | AC | 65 ms
50,820 KB |
testcase_16 | WA | - |
testcase_17 | AC | 65 ms
50,336 KB |
testcase_18 | AC | 66 ms
50,656 KB |
testcase_19 | AC | 68 ms
51,028 KB |
testcase_20 | WA | - |
testcase_21 | AC | 65 ms
50,956 KB |
testcase_22 | AC | 65 ms
50,464 KB |
testcase_23 | AC | 74 ms
50,664 KB |
testcase_24 | AC | 74 ms
50,716 KB |
testcase_25 | AC | 67 ms
50,784 KB |
testcase_26 | AC | 68 ms
50,756 KB |
testcase_27 | AC | 67 ms
50,568 KB |
testcase_28 | AC | 66 ms
50,540 KB |
testcase_29 | AC | 65 ms
50,664 KB |
testcase_30 | AC | 65 ms
50,672 KB |
testcase_31 | WA | - |
testcase_32 | AC | 67 ms
50,792 KB |
testcase_33 | AC | 67 ms
50,532 KB |
testcase_34 | AC | 66 ms
51,020 KB |
testcase_35 | AC | 66 ms
50,956 KB |
testcase_36 | AC | 68 ms
50,852 KB |
testcase_37 | AC | 70 ms
50,660 KB |
testcase_38 | AC | 66 ms
50,744 KB |
testcase_39 | AC | 66 ms
50,624 KB |
testcase_40 | AC | 65 ms
50,520 KB |
testcase_41 | AC | 68 ms
50,652 KB |
ソースコード
/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Ideone { public static void main (String[] args) throws java.lang.Exception { // your code goes here BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); ArrayList<Integer> toy = new ArrayList<Integer>(); int toy_sum = 0; for(String st:br.readLine().split(" ")){ int t = Integer.parseInt(st); toy.add(t); toy_sum += t; } Collections.sort(toy,(a,b)->{return b-a;}); int m = Integer.parseInt(br.readLine()); ArrayList<Integer> box = new ArrayList<Integer>(); for(String st:br.readLine().split(" ")){ box.add(Integer.parseInt(st)); } Collections.sort(box,(a,b)->{return b-a;}); int min = 1; int max = m; int ans = -1; while(max>=min){ int ave = (min+max)/2; if(check(new ArrayList<Integer>(box.subList(0,ave)),new ArrayList<Integer>(toy),toy_sum)){ ans = ave; max = ave-1; }else{ min = ave+1; } } System.out.println(ans); } public static boolean check(ArrayList<Integer> box,ArrayList<Integer> toy,int toy_sum){ for(int b:box){ toy_sum-=b; } if(toy_sum>0){ return false; } for(int i=0;i<toy.size();i++){ int idx = box.indexOf(toy.get(i)); if(idx >= 0){ toy.remove(i); i--; box.set(idx,0); } } Collections.sort(box,(a,b)->{return b-a;}); for(int i=0;i<toy.size();i++){ int bo = box.get(0); int n = toy.get(i); if(bo>=n){ box.set(0,bo-n); Collections.sort(box,(a,b)->{return b-a;}); }else{ return false; } } return true; } }