結果

問題 No.5 数字のブロック
ユーザー maruyuki95maruyuki95
提出日時 2020-05-21 16:58:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 284 ms / 5,000 ms
コード長 784 bytes
コンパイル時間 2,135 ms
コンパイル使用メモリ 74,720 KB
実行使用メモリ 59,256 KB
最終ジャッジ日時 2024-04-09 23:25:13
合計ジャッジ時間 10,007 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 136 ms
54,208 KB
testcase_01 AC 135 ms
53,856 KB
testcase_02 AC 134 ms
54,276 KB
testcase_03 AC 243 ms
58,060 KB
testcase_04 AC 223 ms
57,524 KB
testcase_05 AC 260 ms
58,364 KB
testcase_06 AC 242 ms
58,112 KB
testcase_07 AC 234 ms
57,956 KB
testcase_08 AC 250 ms
58,416 KB
testcase_09 AC 208 ms
56,856 KB
testcase_10 AC 259 ms
58,040 KB
testcase_11 AC 232 ms
58,000 KB
testcase_12 AC 248 ms
58,180 KB
testcase_13 AC 259 ms
58,504 KB
testcase_14 AC 149 ms
54,120 KB
testcase_15 AC 161 ms
54,368 KB
testcase_16 AC 264 ms
58,268 KB
testcase_17 AC 274 ms
58,956 KB
testcase_18 AC 276 ms
59,256 KB
testcase_19 AC 284 ms
59,100 KB
testcase_20 AC 136 ms
54,224 KB
testcase_21 AC 135 ms
53,856 KB
testcase_22 AC 136 ms
54,064 KB
testcase_23 AC 134 ms
53,944 KB
testcase_24 AC 161 ms
54,356 KB
testcase_25 AC 190 ms
54,176 KB
testcase_26 AC 137 ms
54,204 KB
testcase_27 AC 136 ms
54,336 KB
testcase_28 AC 135 ms
53,888 KB
testcase_29 AC 227 ms
57,896 KB
testcase_30 AC 212 ms
56,748 KB
testcase_31 AC 136 ms
54,076 KB
testcase_32 AC 135 ms
54,352 KB
testcase_33 AC 137 ms
54,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int boxWidth = sc.nextInt();
		int blockNum = sc.nextInt();
		int[] blockWidths = new int[blockNum];
		for (int i = 0; i < blockNum; i++) {
			blockWidths[i] = sc.nextInt();
		}

		int ret = new Main().execute(boxWidth, blockNum, blockWidths);
		System.out.println(ret);
	}

	private int execute(int boxWidth, int blockNum, int[] blockWidths) {
		int[] sortedBlockWidths = blockWidths.clone();
		Arrays.parallelSort(sortedBlockWidths);

		int sumWidth = 0;
		for (int i = 0; i < sortedBlockWidths.length; i++) {
			sumWidth += sortedBlockWidths[i];
			if (boxWidth < sumWidth) {
				return i;
			}
		}

		return blockNum;
	}


}
0