結果

問題 No.5 数字のブロック
ユーザー aaaaasatoriaaaaasatori
提出日時 2018-02-05 10:42:16
言語 Java21
(openjdk 21)
結果
AC  
実行時間 530 ms / 5,000 ms
コード長 663 bytes
コンパイル時間 3,707 ms
コンパイル使用メモリ 74,692 KB
実行使用メモリ 47,496 KB
最終ジャッジ日時 2024-04-29 09:36:41
合計ジャッジ時間 14,136 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
41,056 KB
testcase_01 AC 145 ms
41,140 KB
testcase_02 AC 137 ms
41,260 KB
testcase_03 AC 396 ms
46,904 KB
testcase_04 AC 333 ms
46,708 KB
testcase_05 AC 488 ms
46,792 KB
testcase_06 AC 346 ms
46,984 KB
testcase_07 AC 319 ms
46,600 KB
testcase_08 AC 364 ms
46,828 KB
testcase_09 AC 248 ms
43,496 KB
testcase_10 AC 440 ms
47,440 KB
testcase_11 AC 315 ms
46,792 KB
testcase_12 AC 391 ms
47,040 KB
testcase_13 AC 423 ms
46,884 KB
testcase_14 AC 144 ms
41,332 KB
testcase_15 AC 154 ms
41,472 KB
testcase_16 AC 440 ms
47,088 KB
testcase_17 AC 526 ms
47,256 KB
testcase_18 AC 490 ms
47,496 KB
testcase_19 AC 530 ms
47,264 KB
testcase_20 AC 130 ms
41,520 KB
testcase_21 AC 127 ms
41,212 KB
testcase_22 AC 130 ms
41,048 KB
testcase_23 AC 116 ms
40,040 KB
testcase_24 AC 160 ms
41,860 KB
testcase_25 AC 193 ms
42,192 KB
testcase_26 AC 132 ms
41,332 KB
testcase_27 AC 127 ms
41,020 KB
testcase_28 AC 133 ms
41,312 KB
testcase_29 AC 316 ms
46,616 KB
testcase_30 AC 250 ms
43,752 KB
testcase_31 AC 134 ms
41,000 KB
testcase_32 AC 131 ms
41,008 KB
testcase_33 AC 116 ms
39,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class No5 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int L = sc.nextInt(); //箱の幅
		int N = sc.nextInt(); //ブロックの数
		int W[] = new int[N]; //各ブロックの幅
		int x;
		int sum = 0;
		int count;
		
		for(int i = 0;i < N;i++) {
			W[i] = sc.nextInt();
		}
		
		for(int i = 0;i < N;i++) { //Wを昇順にソート
			for(int j = i + 1;j < N;j++) {
				if(W[i] > W[j]) {
					x = W[i];
					W[i] = W[j];
					W[j] = x;
				}
			}
		}
		
		for(count = 0;count < N;count++) {
			sum += W[count];
			if(sum > L) {
				break;
			}
		}
		
		System.out.println(count);
	}
}
0