結果

問題 No.50 おもちゃ箱
ユーザー kou6839
提出日時 2014-12-19 15:58:07
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 973 bytes
コンパイル時間 2,449 ms
コンパイル使用メモリ 77,216 KB
実行使用メモリ 41,796 KB
最終ジャッジ日時 2024-06-12 01:48:39
合計ジャッジ時間 9,846 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 29 WA * 9
権限があれば一括ダウンロードができます

ソースコード

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