結果

問題 No.5 数字のブロック
ユーザー shinwisteriashinwisteria
提出日時 2017-03-18 20:11:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 258 ms / 5,000 ms
コード長 470 bytes
コンパイル時間 4,548 ms
コンパイル使用メモリ 73,208 KB
実行使用メモリ 60,820 KB
最終ジャッジ日時 2023-08-11 17:12:42
合計ジャッジ時間 11,113 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
56,032 KB
testcase_01 AC 123 ms
55,900 KB
testcase_02 AC 123 ms
55,828 KB
testcase_03 AC 215 ms
59,764 KB
testcase_04 AC 210 ms
59,044 KB
testcase_05 AC 241 ms
60,252 KB
testcase_06 AC 216 ms
59,248 KB
testcase_07 AC 215 ms
59,616 KB
testcase_08 AC 226 ms
59,304 KB
testcase_09 AC 197 ms
58,080 KB
testcase_10 AC 246 ms
59,920 KB
testcase_11 AC 216 ms
57,076 KB
testcase_12 AC 228 ms
59,552 KB
testcase_13 AC 243 ms
59,820 KB
testcase_14 AC 134 ms
55,800 KB
testcase_15 AC 155 ms
55,828 KB
testcase_16 AC 239 ms
59,744 KB
testcase_17 AC 253 ms
60,204 KB
testcase_18 AC 250 ms
60,280 KB
testcase_19 AC 258 ms
60,820 KB
testcase_20 AC 126 ms
55,644 KB
testcase_21 AC 126 ms
56,068 KB
testcase_22 AC 123 ms
55,784 KB
testcase_23 AC 123 ms
55,900 KB
testcase_24 AC 153 ms
56,108 KB
testcase_25 AC 178 ms
56,888 KB
testcase_26 AC 124 ms
55,988 KB
testcase_27 AC 122 ms
55,768 KB
testcase_28 AC 121 ms
56,620 KB
testcase_29 AC 211 ms
59,120 KB
testcase_30 AC 196 ms
58,448 KB
testcase_31 AC 124 ms
56,048 KB
testcase_32 AC 121 ms
55,808 KB
testcase_33 AC 122 ms
55,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class NumberBlock {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int L = s.nextInt(), N = s.nextInt(), sum = 0;
		
		int[] W = new int[N];
		for(int i = 0;i<N;i++){
			W[i] = s.nextInt();
		}
		s.close();
		Arrays.sort(W);
		int t=0;
		do{
			sum += W[t++];
		}while(sum <= L && t< N);
		if(sum > L){
			System.out.println(t-1);
		}else{
			System.out.println(t);
		}
	}

}
0