結果

問題 No.50 おもちゃ箱
ユーザー tentententen
提出日時 2020-11-30 09:47:54
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,171 bytes
コンパイル時間 2,735 ms
コンパイル使用メモリ 76,608 KB
実行使用メモリ 56,804 KB
最終ジャッジ日時 2023-10-11 02:47:12
合計ジャッジ時間 10,534 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 124 ms
56,172 KB
testcase_04 AC 123 ms
56,160 KB
testcase_05 AC 124 ms
56,472 KB
testcase_06 AC 124 ms
55,984 KB
testcase_07 AC 124 ms
55,864 KB
testcase_08 AC 123 ms
56,124 KB
testcase_09 AC 123 ms
55,936 KB
testcase_10 AC 123 ms
55,668 KB
testcase_11 WA -
testcase_12 AC 123 ms
55,992 KB
testcase_13 AC 122 ms
56,360 KB
testcase_14 AC 123 ms
56,524 KB
testcase_15 AC 121 ms
56,276 KB
testcase_16 AC 123 ms
55,876 KB
testcase_17 AC 123 ms
56,116 KB
testcase_18 AC 123 ms
56,116 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 125 ms
55,916 KB
testcase_22 AC 123 ms
56,300 KB
testcase_23 AC 123 ms
56,236 KB
testcase_24 AC 122 ms
55,980 KB
testcase_25 AC 122 ms
56,236 KB
testcase_26 AC 123 ms
56,044 KB
testcase_27 AC 123 ms
56,044 KB
testcase_28 AC 123 ms
56,556 KB
testcase_29 AC 124 ms
56,160 KB
testcase_30 AC 125 ms
56,448 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 122 ms
56,368 KB
testcase_34 AC 128 ms
55,852 KB
testcase_35 WA -
testcase_36 AC 126 ms
56,664 KB
testcase_37 AC 125 ms
56,136 KB
testcase_38 AC 124 ms
54,436 KB
testcase_39 AC 125 ms
56,220 KB
testcase_40 AC 123 ms
54,272 KB
testcase_41 AC 124 ms
56,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	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 right = m - 1;
		TreeMap<Integer, Integer> using = new TreeMap<>();
		using.put(Integer.MAX_VALUE, 0);
		for (int i = n - 1; i >= 0; i--) {
		    int key = using.ceilingKey(toys[i]);
		    if (key == Integer.MAX_VALUE) {
		        if (right < 0 || boxes[right] < toys[i]) {
		            System.out.println(-1);
		            return;
		        }
		        using.put(boxes[right] - toys[i], using.getOrDefault(boxes[right] - toys[i], 0) + 1);
		        right--;
		    } else {
		        if (using.get(key) == 1) {
		            using.remove(key);
		        } else {
		            using.put(key, using.get(key) - 1);
		        }
	            using.put(key - toys[i], using.getOrDefault(key - toys[i], 0) + 1);
		    }
		}
		System.out.println(m - right - 1);
	}
}

0