結果

問題 No.5 数字のブロック
ユーザー omc-test
提出日時 2016-08-03 13:12:53
言語 Java
(openjdk 23)
結果
AC  
実行時間 293 ms / 5,000 ms
コード長 589 bytes
コンパイル時間 2,307 ms
コンパイル使用メモリ 75,940 KB
実行使用メモリ 48,300 KB
最終ジャッジ日時 2024-11-18 08:49:19
合計ジャッジ時間 10,106 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int l = sc.nextInt();
		int n = sc.nextInt();
		List<Integer> w = new ArrayList<Integer>();
		for(int i=0; i<n; i++){
			w.add(sc.nextInt());
		}
		sc.close();
		Collections.sort(w);
		int sum = 0;
		int count;
		for(count = 0; count<w.size(); count++){
			if(l >= sum + w.get(count)){
				sum = sum + w.get(count);
			}else{
				break;
			}
		}
		System.out.println(count);
	}
}
0