結果

問題 No.50 おもちゃ箱
ユーザー リチウムリチウム
提出日時 2014-10-27 00:01:08
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 793 bytes
コンパイル時間 2,397 ms
コンパイル使用メモリ 73,740 KB
実行使用メモリ 57,972 KB
最終ジャッジ日時 2023-08-28 23:08:53
合計ジャッジ時間 9,436 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 127 ms
56,152 KB
testcase_04 AC 128 ms
55,708 KB
testcase_05 AC 127 ms
56,148 KB
testcase_06 AC 127 ms
55,952 KB
testcase_07 AC 126 ms
55,492 KB
testcase_08 AC 128 ms
56,008 KB
testcase_09 AC 127 ms
55,652 KB
testcase_10 AC 126 ms
55,676 KB
testcase_11 WA -
testcase_12 AC 123 ms
55,480 KB
testcase_13 AC 125 ms
55,936 KB
testcase_14 AC 126 ms
56,156 KB
testcase_15 AC 124 ms
55,656 KB
testcase_16 AC 127 ms
56,136 KB
testcase_17 AC 126 ms
55,448 KB
testcase_18 AC 126 ms
55,672 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 126 ms
55,740 KB
testcase_22 AC 124 ms
55,840 KB
testcase_23 AC 127 ms
53,764 KB
testcase_24 AC 126 ms
55,748 KB
testcase_25 AC 125 ms
56,104 KB
testcase_26 AC 125 ms
56,244 KB
testcase_27 AC 127 ms
55,880 KB
testcase_28 AC 124 ms
56,148 KB
testcase_29 AC 126 ms
55,860 KB
testcase_30 AC 123 ms
55,860 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 124 ms
56,232 KB
testcase_34 AC 123 ms
56,152 KB
testcase_35 WA -
testcase_36 AC 123 ms
55,780 KB
testcase_37 AC 125 ms
55,592 KB
testcase_38 AC 125 ms
56,200 KB
testcase_39 AC 122 ms
55,664 KB
testcase_40 AC 126 ms
56,144 KB
testcase_41 AC 125 ms
55,996 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;
				}
			}
			if(used)ans++;
		}
		for(int i=0;i<n;i++){
			if(!t[i]){
				System.out.println(-1);
				return;
			}
		}
	    System.out.println(ans);
	}}
0