結果

問題 No.5 数字のブロック
ユーザー AoiroFukurou
提出日時 2016-05-19 14:33:07
言語 Java
(openjdk 23)
結果
AC  
実行時間 245 ms / 5,000 ms
コード長 517 bytes
コンパイル時間 3,730 ms
コンパイル使用メモリ 75,476 KB
実行使用メモリ 47,896 KB
最終ジャッジ日時 2024-11-18 08:37:33
合計ジャッジ時間 10,098 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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();
		}
		sc.close();
		
		Arrays.sort(w);//ソート
		
		for (int n : w) {
			if (L - tmp >= n) {
				tmp += n;
				c++;
			} else {
				break;
			}
		}
		System.out.println(c);
	}
}
0