結果

問題 No.5 数字のブロック
ユーザー oyafuso
提出日時 2019-03-11 17:55:16
言語 Java
(openjdk 23)
結果
AC  
実行時間 235 ms / 5,000 ms
コード長 950 bytes
コンパイル時間 2,183 ms
コンパイル使用メモリ 76,872 KB
実行使用メモリ 43,924 KB
最終ジャッジ日時 2024-11-18 13:00:44
合計ジャッジ時間 8,979 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class Main {

	private static final String SPLIT_STR = " ";

	public static void main(String[] args) {
		// Scanner生成
		Scanner sc = new Scanner(System.in);
		// 入力設定
		String input = sc.nextLine();
		int L = Integer.parseInt(input);
		sc.reset();
		input = sc.nextLine();
		sc.reset();
		input = sc.nextLine();
		String[] split = input.split(SPLIT_STR);
		List<Integer> numList = new ArrayList<>(split.length);
		for (int i = 0; i < split.length; i++) {
			numList.add(Integer.parseInt(split[i]));
		}
		// Scannerクローズ
		sc.close();

		/* メイン処理開始 */
		// 変数初期化
		int result = 0;
		int remain = L;
		// 結果設定
		Collections.sort(numList);
		for (int i = 0; i < numList.size(); i++) {
			if (remain >= numList.get(i)) {
				remain -= numList.get(i);
				result++;
			} else {
				break;
			}
		}
		/* メイン処理終了 */

		// 結果出力
		System.out.println(result);
	}
}
0