結果

問題 No.5 数字のブロック
ユーザー YOSHIYOSHI
提出日時 2021-02-17 10:27:02
言語 Java21
(openjdk 21)
結果
AC  
実行時間 229 ms / 5,000 ms
コード長 857 bytes
コンパイル時間 6,646 ms
コンパイル使用メモリ 79,944 KB
実行使用メモリ 59,988 KB
最終ジャッジ日時 2023-10-11 21:52:34
合計ジャッジ時間 14,111 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,524 KB
testcase_01 AC 126 ms
55,728 KB
testcase_02 AC 127 ms
55,988 KB
testcase_03 AC 209 ms
57,428 KB
testcase_04 AC 177 ms
55,932 KB
testcase_05 AC 212 ms
57,492 KB
testcase_06 AC 201 ms
57,936 KB
testcase_07 AC 198 ms
57,172 KB
testcase_08 AC 205 ms
57,384 KB
testcase_09 AC 169 ms
55,924 KB
testcase_10 AC 220 ms
57,596 KB
testcase_11 AC 203 ms
57,380 KB
testcase_12 AC 208 ms
57,120 KB
testcase_13 AC 215 ms
57,548 KB
testcase_14 AC 131 ms
55,904 KB
testcase_15 AC 133 ms
55,800 KB
testcase_16 AC 220 ms
57,536 KB
testcase_17 AC 226 ms
57,976 KB
testcase_18 AC 222 ms
57,296 KB
testcase_19 AC 229 ms
59,988 KB
testcase_20 AC 128 ms
55,716 KB
testcase_21 AC 128 ms
56,000 KB
testcase_22 AC 126 ms
55,732 KB
testcase_23 AC 127 ms
56,176 KB
testcase_24 AC 136 ms
54,364 KB
testcase_25 AC 147 ms
55,536 KB
testcase_26 AC 126 ms
55,812 KB
testcase_27 AC 127 ms
55,916 KB
testcase_28 AC 128 ms
56,072 KB
testcase_29 AC 176 ms
55,864 KB
testcase_30 AC 168 ms
55,960 KB
testcase_31 AC 127 ms
55,516 KB
testcase_32 AC 126 ms
55,704 KB
testcase_33 AC 128 ms
55,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Stream;

public class No00000005_Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int lineCnt = 0;
		int l = 0;
		int n = 0;
		String[] wiStr = null;

		while(scan.hasNextLine()) {
			lineCnt++;
			if(lineCnt == 1) {
				l = Integer.parseInt(scan.nextLine());
			} else if(lineCnt == 2) {
				n =  Integer.parseInt(scan.nextLine());
			} else if(lineCnt == 3) {
				wiStr = scan.nextLine().split(" ");
			}
			if(lineCnt == 3) {
				break;
			}
		}

		int[] wiInt = Stream.of(wiStr).mapToInt(Integer::parseInt).toArray();
		Arrays.sort(wiInt);

		int cnt = 0;
		int sum = 0;
		for(int i = 0; i < n; i++) {
			if(sum + wiInt[i] > l) {
				break;
			}
			sum += wiInt[i];
			cnt++;
		}

		System.out.println(cnt);

		scan.close();

	}

}
0