結果

問題 No.5 数字のブロック
ユーザー hhgfhn1hhgfhn1
提出日時 2018-08-20 23:49:03
言語 Java21
(openjdk 21)
結果
AC  
実行時間 299 ms / 5,000 ms
コード長 618 bytes
コンパイル時間 2,285 ms
コンパイル使用メモリ 75,904 KB
実行使用メモリ 47,740 KB
最終ジャッジ日時 2024-04-29 09:58:12
合計ジャッジ時間 10,083 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
41,244 KB
testcase_01 AC 117 ms
40,044 KB
testcase_02 AC 130 ms
41,268 KB
testcase_03 AC 256 ms
46,832 KB
testcase_04 AC 225 ms
45,868 KB
testcase_05 AC 274 ms
47,396 KB
testcase_06 AC 248 ms
46,188 KB
testcase_07 AC 235 ms
45,968 KB
testcase_08 AC 244 ms
46,096 KB
testcase_09 AC 209 ms
43,752 KB
testcase_10 AC 276 ms
47,692 KB
testcase_11 AC 238 ms
46,076 KB
testcase_12 AC 253 ms
46,752 KB
testcase_13 AC 275 ms
46,676 KB
testcase_14 AC 141 ms
41,356 KB
testcase_15 AC 150 ms
41,612 KB
testcase_16 AC 271 ms
47,564 KB
testcase_17 AC 291 ms
47,736 KB
testcase_18 AC 280 ms
47,564 KB
testcase_19 AC 299 ms
47,740 KB
testcase_20 AC 132 ms
41,000 KB
testcase_21 AC 134 ms
41,108 KB
testcase_22 AC 131 ms
41,180 KB
testcase_23 AC 117 ms
40,112 KB
testcase_24 AC 153 ms
41,400 KB
testcase_25 AC 178 ms
41,996 KB
testcase_26 AC 131 ms
41,252 KB
testcase_27 AC 130 ms
41,092 KB
testcase_28 AC 128 ms
41,224 KB
testcase_29 AC 237 ms
45,896 KB
testcase_30 AC 214 ms
43,932 KB
testcase_31 AC 131 ms
41,000 KB
testcase_32 AC 131 ms
41,248 KB
testcase_33 AC 133 ms
41,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

class sampleA {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int l = scan.nextInt();
		int n = scan.nextInt();
		int answer = 0;
		List<Integer> blocksLength = new ArrayList<>();
		int sumW = 0;

		for (int i = 0; i < n; i++) {
			blocksLength.add(scan.nextInt());
		}

		scan.close();
		Collections.sort(blocksLength);

		for (int w : blocksLength) {
			if (sumW + w <= l) {
				sumW += w;
				answer++;

			} else {
				break;
			}
		}
		System.out.print(answer);
	}
}
0