結果

問題 No.5 数字のブロック
ユーザー h_tyokinuhata
提出日時 2015-12-19 23:30:25
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 555 bytes
コンパイル時間 2,138 ms
コンパイル使用メモリ 76,708 KB
実行使用メモリ 59,152 KB
最終ジャッジ日時 2024-09-17 11:00:34
合計ジャッジ時間 9,403 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
 
class Main {
    public static void main(String[] args) {
    	
    	Scanner sc = new Scanner(System.in);
    	ArrayList<Integer> W = new ArrayList<>();

    	int L = sc.nextInt();
    	int N = sc.nextInt();
    	for(int i = 0; i < N; i++) {
    		W.add(sc.nextInt());
    	}
    	Collections.sort(W);
    	int i = 0;
    	while(L >= 0 && i < N) {
   	   		L = L - W.get(i);
   	   		System.out.println(L);
   	   		if(L >= 0) {
   	   			i++;
   	   		} else {
   	   			break;
   	   		}
    	}
    	System.out.println(i);
    }
}
0