結果

問題 No.50 おもちゃ箱
ユーザー htensaihtensai
提出日時 2019-12-06 21:17:24
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 966 bytes
コンパイル時間 2,358 ms
コンパイル使用メモリ 74,644 KB
実行使用メモリ 58,564 KB
最終ジャッジ日時 2023-08-25 13:14:18
合計ジャッジ時間 10,531 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 122 ms
56,088 KB
testcase_04 AC 121 ms
55,932 KB
testcase_05 AC 125 ms
56,288 KB
testcase_06 AC 122 ms
56,080 KB
testcase_07 AC 120 ms
55,976 KB
testcase_08 AC 122 ms
55,860 KB
testcase_09 AC 122 ms
56,200 KB
testcase_10 AC 122 ms
55,840 KB
testcase_11 WA -
testcase_12 AC 125 ms
56,132 KB
testcase_13 AC 121 ms
56,072 KB
testcase_14 AC 120 ms
56,044 KB
testcase_15 AC 119 ms
56,184 KB
testcase_16 AC 121 ms
55,980 KB
testcase_17 AC 120 ms
55,524 KB
testcase_18 AC 119 ms
56,080 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 125 ms
56,108 KB
testcase_22 AC 120 ms
55,768 KB
testcase_23 AC 119 ms
55,904 KB
testcase_24 AC 116 ms
55,792 KB
testcase_25 AC 118 ms
56,324 KB
testcase_26 AC 119 ms
55,552 KB
testcase_27 AC 123 ms
56,108 KB
testcase_28 AC 131 ms
55,564 KB
testcase_29 AC 123 ms
56,312 KB
testcase_30 AC 122 ms
55,748 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 120 ms
56,056 KB
testcase_34 AC 119 ms
55,980 KB
testcase_35 WA -
testcase_36 AC 120 ms
56,096 KB
testcase_37 AC 120 ms
56,076 KB
testcase_38 AC 120 ms
55,900 KB
testcase_39 AC 120 ms
56,508 KB
testcase_40 AC 121 ms
56,028 KB
testcase_41 AC 121 ms
55,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static HashSet<String> set = new HashSet<>();
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] toys = new int[n];
		for (int i = 0; i < n; i++) {
		    toys[i] = sc.nextInt();
		}
		Arrays.sort(toys);
		int m = sc.nextInt();
		int[] boxes = new int[m];
		for (int i = 0; i < m; i++) {
		    boxes[i] = sc.nextInt();
		}
		Arrays.sort(boxes);
		int idx = m;
		for (int i = n - 1; i >= 0; i--) {
		    if (toys[i] == 0) {
		        continue;
		    }
		    idx--;
		    if (idx < 0 || boxes[idx] < toys[i]) {
		        System.out.println(-1);
		        return;
		    }
		    int remain = boxes[idx] - toys[i];
		    int left = i - 1;
		    while (remain > 0 && left >= 0) {
		        if (remain >= toys[left]) {
		            remain -= toys[left];
		            toys[left] = 0;
		        }
		        left--;
		    }
		}
		System.out.println(m - idx);
   }
}

0