結果

問題 No.5 数字のブロック
ユーザー Tsukasa_Type
提出日時 2018-02-09 00:48:26
言語 Java
(openjdk 23)
結果
AC  
実行時間 260 ms / 5,000 ms
コード長 453 bytes
コンパイル時間 2,247 ms
コンパイル使用メモリ 74,304 KB
実行使用メモリ 59,060 KB
最終ジャッジ日時 2024-11-18 12:05:22
合計ジャッジ時間 9,133 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int L = sc.nextInt();
		int n = sc.nextInt();
		int[] ints = new int[n];
		for (int i=0; i<n; i++) {
			ints[i] = sc.nextInt();
		}
		Arrays.sort(ints);
		int count = 0;
		int length = 0;
		for (int i=0; i<n; i++) {
			length += ints[i];
			if (length <= L) {count++;}
			else {break;}
		}
		System.out.println(count);
	}
}
0