結果

問題 No.5 数字のブロック
ユーザー takutakutakutaku
提出日時 2020-09-16 11:56:47
言語 Java21
(openjdk 21)
結果
AC  
実行時間 223 ms / 5,000 ms
コード長 737 bytes
コンパイル時間 4,536 ms
コンパイル使用メモリ 71,376 KB
実行使用メモリ 60,572 KB
最終ジャッジ日時 2023-09-04 03:25:50
合計ジャッジ時間 10,030 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,588 KB
testcase_01 AC 122 ms
55,800 KB
testcase_02 AC 121 ms
55,440 KB
testcase_03 AC 203 ms
59,960 KB
testcase_04 AC 193 ms
59,128 KB
testcase_05 AC 214 ms
58,032 KB
testcase_06 AC 196 ms
58,804 KB
testcase_07 AC 193 ms
58,776 KB
testcase_08 AC 202 ms
59,332 KB
testcase_09 AC 180 ms
56,524 KB
testcase_10 AC 211 ms
59,684 KB
testcase_11 AC 190 ms
58,420 KB
testcase_12 AC 207 ms
59,484 KB
testcase_13 AC 217 ms
59,884 KB
testcase_14 AC 129 ms
55,728 KB
testcase_15 AC 135 ms
55,944 KB
testcase_16 AC 211 ms
59,748 KB
testcase_17 AC 218 ms
60,316 KB
testcase_18 AC 214 ms
59,612 KB
testcase_19 AC 223 ms
60,572 KB
testcase_20 AC 121 ms
53,988 KB
testcase_21 AC 119 ms
55,896 KB
testcase_22 AC 119 ms
55,500 KB
testcase_23 AC 120 ms
56,120 KB
testcase_24 AC 139 ms
55,868 KB
testcase_25 AC 149 ms
55,804 KB
testcase_26 AC 120 ms
55,740 KB
testcase_27 AC 121 ms
55,776 KB
testcase_28 AC 120 ms
55,584 KB
testcase_29 AC 188 ms
58,696 KB
testcase_30 AC 181 ms
56,752 KB
testcase_31 AC 120 ms
56,056 KB
testcase_32 AC 134 ms
55,696 KB
testcase_33 AC 119 ms
55,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main(String[] args) {
	    
	    // 入力値を取得
		Scanner sc = new Scanner(System.in);
		int l = sc.nextInt();
		int n = sc.nextInt();
		
		// ブロックは配列に格納する
		int[] numbers = new int[n];
		for(int i = 0; i < n; i++) {
		    numbers[i] = Integer.parseInt(sc.next());
		}
		sc.close();
		
		// 配列の要素をソートする
		Arrays.sort(numbers);
		int value = 0;
		int count = 0;
		
		// ブロックを小さい順に足し算し、箱に入るブロック数を探索する
		for(int i = 0; i < n; i++) {
		    value += numbers[i];
		    if(value <= l) {
		        count++;
		    }
		}
		
		// 出力
		System.out.println(count);
	    
	}
}
0