結果

問題 No.5 数字のブロック
ユーザー AoiroFukurou
提出日時 2016-05-19 14:21:37
言語 Java
(openjdk 23)
結果
AC  
実行時間 253 ms / 5,000 ms
コード長 539 bytes
コンパイル時間 2,819 ms
コンパイル使用メモリ 75,200 KB
実行使用メモリ 59,084 KB
最終ジャッジ日時 2024-11-18 08:36:56
合計ジャッジ時間 9,476 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.Arrays;
import java.util.Scanner;

public class No5v2 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int L = sc.nextInt();
		int N = sc.nextInt();
		int[] w = new int[N];
		int tmp = 0;
		int c = 0;
		for (int i = 0; i < w.length; i++) {
			w[i] = sc.nextInt();
		}
		Arrays.sort(w);//ソート
		
		for (int i = 0; i < w.length; i++) {
			if (L - tmp >= w[i]) {
				tmp += w[i];
				c++;
			} else {
				break;
			}
		}
		System.out.println(c);
		sc.close();
	}
}
0