結果

問題 No.50 おもちゃ箱
ユーザー kou6839kou6839
提出日時 2014-12-19 15:58:07
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 973 bytes
コンパイル時間 3,519 ms
コンパイル使用メモリ 73,896 KB
実行使用メモリ 57,684 KB
最終ジャッジ日時 2023-09-02 19:24:15
合計ジャッジ時間 9,786 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 124 ms
55,620 KB
testcase_04 AC 123 ms
55,648 KB
testcase_05 AC 125 ms
56,272 KB
testcase_06 AC 123 ms
55,620 KB
testcase_07 AC 123 ms
55,580 KB
testcase_08 AC 125 ms
55,876 KB
testcase_09 AC 124 ms
55,872 KB
testcase_10 AC 124 ms
56,080 KB
testcase_11 WA -
testcase_12 AC 123 ms
55,988 KB
testcase_13 AC 123 ms
55,388 KB
testcase_14 AC 124 ms
55,816 KB
testcase_15 AC 124 ms
55,724 KB
testcase_16 AC 125 ms
55,904 KB
testcase_17 AC 123 ms
55,732 KB
testcase_18 AC 123 ms
57,684 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 125 ms
55,744 KB
testcase_22 AC 123 ms
55,548 KB
testcase_23 AC 123 ms
55,716 KB
testcase_24 AC 122 ms
56,260 KB
testcase_25 AC 122 ms
55,936 KB
testcase_26 AC 123 ms
55,716 KB
testcase_27 AC 122 ms
55,612 KB
testcase_28 AC 124 ms
55,936 KB
testcase_29 AC 123 ms
55,692 KB
testcase_30 AC 124 ms
56,076 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 124 ms
55,820 KB
testcase_34 AC 124 ms
55,844 KB
testcase_35 WA -
testcase_36 AC 122 ms
55,740 KB
testcase_37 AC 123 ms
55,820 KB
testcase_38 AC 123 ms
55,944 KB
testcase_39 AC 123 ms
55,716 KB
testcase_40 AC 123 ms
55,832 KB
testcase_41 AC 127 ms
55,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.*;
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n= sc.nextInt();
        int[] omo = new int[n];
        for(int i=0;i<n;i++){
        	omo[i]=sc.nextInt();
        }
        Arrays.sort(omo);
        int m = sc.nextInt();
        int[] hako =new int[m];
        boolean[] use = new boolean[m];
        for(int i=0;i<m;i++){
        	hako[i]=sc.nextInt();
        }
        Arrays.sort(hako);
        for(int i=n-1;i>=0;i--){
        	for(int j=m-1;j>=0;j--){
        		if(omo[i]<=hako[j]){
        			hako[j]-=omo[i];
        			use[j]=true;
        			break;
        		}else{
        			if(j==0){
        				System.out.println(-1);
        				return;
        			}
        			continue;
        		}
        	}
        }
        int ans=0;
        for(int i=0;i<m;i++){
        	if(use[i])ans++;
        }
        System.out.println(ans);
        
    }
}	
0