結果

問題 No.50 おもちゃ箱
ユーザー kou6839kou6839
提出日時 2014-12-19 15:58:07
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 973 bytes
コンパイル時間 2,449 ms
コンパイル使用メモリ 77,216 KB
実行使用メモリ 41,796 KB
最終ジャッジ日時 2024-06-12 01:48:39
合計ジャッジ時間 9,846 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 137 ms
41,128 KB
testcase_04 AC 133 ms
41,092 KB
testcase_05 AC 135 ms
41,420 KB
testcase_06 AC 137 ms
41,056 KB
testcase_07 AC 138 ms
41,128 KB
testcase_08 AC 138 ms
41,388 KB
testcase_09 AC 134 ms
41,292 KB
testcase_10 AC 136 ms
41,372 KB
testcase_11 WA -
testcase_12 AC 138 ms
41,384 KB
testcase_13 AC 135 ms
41,728 KB
testcase_14 AC 138 ms
41,656 KB
testcase_15 AC 135 ms
41,248 KB
testcase_16 AC 137 ms
41,504 KB
testcase_17 AC 136 ms
41,132 KB
testcase_18 AC 140 ms
41,176 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 142 ms
41,512 KB
testcase_22 AC 133 ms
41,080 KB
testcase_23 AC 135 ms
41,436 KB
testcase_24 AC 132 ms
41,528 KB
testcase_25 AC 133 ms
41,656 KB
testcase_26 AC 136 ms
41,048 KB
testcase_27 AC 139 ms
41,348 KB
testcase_28 AC 136 ms
41,596 KB
testcase_29 AC 136 ms
41,332 KB
testcase_30 AC 138 ms
41,440 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 138 ms
41,168 KB
testcase_34 AC 135 ms
41,620 KB
testcase_35 WA -
testcase_36 AC 137 ms
41,776 KB
testcase_37 AC 139 ms
41,180 KB
testcase_38 AC 122 ms
40,252 KB
testcase_39 AC 141 ms
41,796 KB
testcase_40 AC 137 ms
41,224 KB
testcase_41 AC 135 ms
41,136 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