結果

問題 No.50 おもちゃ箱
ユーザー リチウムリチウム
提出日時 2014-10-26 23:39:27
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 807 bytes
コンパイル時間 1,981 ms
コンパイル使用メモリ 74,124 KB
実行使用メモリ 57,896 KB
最終ジャッジ日時 2023-08-28 23:08:01
合計ジャッジ時間 8,872 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 119 ms
56,128 KB
testcase_04 AC 122 ms
56,112 KB
testcase_05 AC 123 ms
56,272 KB
testcase_06 AC 123 ms
55,884 KB
testcase_07 AC 124 ms
56,464 KB
testcase_08 AC 126 ms
55,836 KB
testcase_09 AC 125 ms
55,964 KB
testcase_10 AC 124 ms
56,116 KB
testcase_11 WA -
testcase_12 AC 118 ms
56,040 KB
testcase_13 AC 120 ms
56,048 KB
testcase_14 AC 121 ms
56,104 KB
testcase_15 AC 122 ms
56,248 KB
testcase_16 AC 120 ms
55,748 KB
testcase_17 AC 121 ms
56,236 KB
testcase_18 AC 122 ms
55,676 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 120 ms
56,072 KB
testcase_22 AC 124 ms
56,568 KB
testcase_23 AC 121 ms
56,152 KB
testcase_24 AC 122 ms
55,704 KB
testcase_25 AC 121 ms
56,068 KB
testcase_26 AC 122 ms
55,792 KB
testcase_27 AC 122 ms
56,044 KB
testcase_28 AC 119 ms
55,816 KB
testcase_29 AC 121 ms
56,076 KB
testcase_30 AC 123 ms
56,204 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 120 ms
55,856 KB
testcase_34 AC 118 ms
55,512 KB
testcase_35 WA -
testcase_36 AC 126 ms
56,168 KB
testcase_37 AC 122 ms
56,416 KB
testcase_38 AC 127 ms
55,820 KB
testcase_39 AC 125 ms
55,964 KB
testcase_40 AC 121 ms
55,696 KB
testcase_41 AC 125 ms
56,144 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 toy[]=new int[n];
		for(int i=0;i<n;i++){
			toy[i]=sc.nextInt();
		}
		int m=sc.nextInt();
		int box[]=new int[m];
		for(int i=0;i<m;i++){
			box[i]=sc.nextInt();
		}
		Arrays.sort(toy);
		Arrays.sort(box);
		int nokori=n;
		int ans=0;
		boolean t[]=new boolean[n];
		for(int i=m-1;i>=0;i--){
			int x=box[i];
			boolean used=false;
			for(int j=n-1;j>=0;j--){
				if(!t[j] && x>=toy[j]){
					t[j]=true;
					x-=toy[j];
	                used=true;
					nokori--;
					if(nokori==0)break;
				}
			}
			if(used)ans++;
			if(nokori==0)break;
		}
		if(nokori>0)System.out.println(-1);
		else System.out.println(ans);
	}}
0