結果

問題 No.5 数字のブロック
ユーザー taku-techtaku-tech
提出日時 2021-05-18 16:41:52
言語 Java21
(openjdk 21)
結果
AC  
実行時間 273 ms / 5,000 ms
コード長 771 bytes
コンパイル時間 3,270 ms
コンパイル使用メモリ 75,036 KB
実行使用メモリ 48,272 KB
最終ジャッジ日時 2024-04-17 05:58:17
合計ジャッジ時間 10,766 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
40,212 KB
testcase_01 AC 111 ms
40,232 KB
testcase_02 AC 114 ms
40,216 KB
testcase_03 AC 241 ms
46,640 KB
testcase_04 AC 217 ms
45,964 KB
testcase_05 AC 248 ms
47,324 KB
testcase_06 AC 234 ms
46,392 KB
testcase_07 AC 221 ms
46,004 KB
testcase_08 AC 235 ms
46,720 KB
testcase_09 AC 192 ms
43,520 KB
testcase_10 AC 244 ms
47,324 KB
testcase_11 AC 221 ms
46,472 KB
testcase_12 AC 237 ms
47,024 KB
testcase_13 AC 242 ms
47,088 KB
testcase_14 AC 133 ms
41,352 KB
testcase_15 AC 148 ms
41,628 KB
testcase_16 AC 257 ms
46,772 KB
testcase_17 AC 251 ms
48,272 KB
testcase_18 AC 249 ms
47,300 KB
testcase_19 AC 273 ms
47,688 KB
testcase_20 AC 117 ms
40,088 KB
testcase_21 AC 130 ms
41,540 KB
testcase_22 AC 123 ms
41,084 KB
testcase_23 AC 122 ms
41,124 KB
testcase_24 AC 142 ms
41,560 KB
testcase_25 AC 167 ms
42,276 KB
testcase_26 AC 126 ms
40,972 KB
testcase_27 AC 126 ms
41,184 KB
testcase_28 AC 125 ms
41,028 KB
testcase_29 AC 202 ms
45,648 KB
testcase_30 AC 206 ms
44,448 KB
testcase_31 AC 116 ms
40,492 KB
testcase_32 AC 120 ms
39,964 KB
testcase_33 AC 129 ms
41,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class BlockOfNumber02 {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int boxWidth = sc.nextInt();	//入れ物となる箱の幅
		int blockNum = sc.nextInt();	//ブロックの数
		int[] arrayBlocksWidth = new int[blockNum];		//各ブロックの幅を格納した配列

		for(int i = 0; i < blockNum; i++) {
			arrayBlocksWidth[i] = sc.nextInt();
		}

		int blockCnt = 0;
		int[] sortedBlock = arrayBlocksWidth.clone();
		Arrays.sort(sortedBlock);
		int space = boxWidth;
		for(int i = 0; i < sortedBlock.length; i++) {
			if(space >= sortedBlock[i]) {
				space -= sortedBlock[i];
				blockCnt++;
			} else {
				break;
			}
		}

		System.out.println(blockCnt);
	}

}
0