結果

問題 No.5 数字のブロック
ユーザー papipenpapipen
提出日時 2017-03-26 14:51:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 258 ms / 5,000 ms
コード長 528 bytes
コンパイル時間 2,117 ms
コンパイル使用メモリ 71,608 KB
実行使用メモリ 61,812 KB
最終ジャッジ日時 2023-08-11 17:14:02
合計ジャッジ時間 9,593 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,656 KB
testcase_01 AC 121 ms
55,436 KB
testcase_02 AC 122 ms
55,432 KB
testcase_03 AC 228 ms
59,308 KB
testcase_04 AC 211 ms
58,768 KB
testcase_05 AC 241 ms
61,812 KB
testcase_06 AC 223 ms
59,140 KB
testcase_07 AC 210 ms
58,744 KB
testcase_08 AC 217 ms
59,636 KB
testcase_09 AC 192 ms
59,088 KB
testcase_10 AC 239 ms
59,628 KB
testcase_11 AC 215 ms
59,424 KB
testcase_12 AC 230 ms
59,800 KB
testcase_13 AC 233 ms
59,968 KB
testcase_14 AC 135 ms
55,620 KB
testcase_15 AC 147 ms
56,052 KB
testcase_16 AC 243 ms
59,904 KB
testcase_17 AC 249 ms
60,656 KB
testcase_18 AC 258 ms
60,468 KB
testcase_19 AC 247 ms
60,168 KB
testcase_20 AC 121 ms
55,640 KB
testcase_21 AC 120 ms
55,824 KB
testcase_22 AC 121 ms
55,720 KB
testcase_23 AC 119 ms
55,624 KB
testcase_24 AC 149 ms
55,876 KB
testcase_25 AC 177 ms
56,712 KB
testcase_26 AC 122 ms
55,648 KB
testcase_27 AC 126 ms
55,784 KB
testcase_28 AC 124 ms
55,644 KB
testcase_29 AC 213 ms
61,328 KB
testcase_30 AC 195 ms
58,184 KB
testcase_31 AC 123 ms
53,644 KB
testcase_32 AC 126 ms
55,616 KB
testcase_33 AC 125 ms
55,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

class Block{
	public static void main(String args[]){
		Scanner s = new Scanner(System.in);
		int L = s.nextInt();
		int N = s.nextInt();
		int W[] = new int[N];
		for(int i = 0; i < N; i++){
			W[i] = s.nextInt();
		}
		Arrays.sort(W);
		
		int sum = 0;
		for(int j = 0; j < N; j++){
			sum += W[j];
			if(sum == L){
				System.out.println(j + 1);
				System.exit(0);
			}else if(sum > L){
				System.out.println(j);
				System.exit(0);
			}
		}
		System.out.println(N);
	}
}
0