結果

問題 No.5 数字のブロック
ユーザー eagleeagle
提出日時 2022-05-26 15:27:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 531 ms / 5,000 ms
コード長 862 bytes
コンパイル時間 1,988 ms
コンパイル使用メモリ 74,768 KB
実行使用メモリ 61,936 KB
最終ジャッジ日時 2023-10-20 19:28:03
合計ジャッジ時間 12,291 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
57,480 KB
testcase_01 AC 131 ms
57,296 KB
testcase_02 AC 132 ms
57,180 KB
testcase_03 AC 378 ms
61,512 KB
testcase_04 AC 293 ms
61,660 KB
testcase_05 AC 432 ms
61,604 KB
testcase_06 AC 341 ms
61,656 KB
testcase_07 AC 272 ms
60,892 KB
testcase_08 AC 354 ms
61,664 KB
testcase_09 AC 236 ms
60,028 KB
testcase_10 AC 440 ms
61,712 KB
testcase_11 AC 309 ms
61,536 KB
testcase_12 AC 376 ms
61,692 KB
testcase_13 AC 418 ms
61,628 KB
testcase_14 AC 142 ms
57,536 KB
testcase_15 AC 153 ms
57,544 KB
testcase_16 AC 432 ms
61,936 KB
testcase_17 AC 510 ms
61,532 KB
testcase_18 AC 485 ms
61,624 KB
testcase_19 AC 531 ms
61,528 KB
testcase_20 AC 133 ms
57,084 KB
testcase_21 AC 131 ms
54,928 KB
testcase_22 AC 132 ms
57,000 KB
testcase_23 AC 136 ms
57,088 KB
testcase_24 AC 170 ms
57,184 KB
testcase_25 AC 199 ms
57,600 KB
testcase_26 AC 131 ms
56,996 KB
testcase_27 AC 132 ms
57,104 KB
testcase_28 AC 131 ms
56,960 KB
testcase_29 AC 304 ms
61,552 KB
testcase_30 AC 246 ms
58,800 KB
testcase_31 AC 132 ms
56,996 KB
testcase_32 AC 132 ms
57,028 KB
testcase_33 AC 135 ms
57,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		//大きな箱の幅
		int L = sc.nextInt();
		//ブロックの数
		int N = sc.nextInt();
		//各ブロックの幅
		int[] W = new int[N];
		for(int i = 0; i < N; i++) {
			W[i] = sc.nextInt();
		}
		//配列Wを小さい順に並び替える
		for(int i = 0; i < N - 1; i++) {
			for(int j = i; j < N; j++) {
				if(W[i] > W[j]) {
					int num = W[i];
					W[i] = W[j];
					W[j] = num;
				}
			}
		}
		//大きな箱に小さい箱から順に入れていく
		int w = 0; //現在の幅
		int ans = 0; //大きな箱に入れた箱の個数
		for(int i = 0; i < N; i++) {
			if(w + W[i] > L) {
				break;
			}
			w += W[i];
			ans++;
		}
		System.out.println(ans);
	}
}
0