結果

問題 No.5 数字のブロック
ユーザー DemocoDemoco
提出日時 2015-05-02 00:49:47
言語 Java21
(openjdk 21)
結果
AC  
実行時間 270 ms / 5,000 ms
コード長 442 bytes
コンパイル時間 2,321 ms
コンパイル使用メモリ 71,396 KB
実行使用メモリ 60,572 KB
最終ジャッジ日時 2023-08-11 08:19:26
合計ジャッジ時間 10,259 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
55,876 KB
testcase_01 AC 133 ms
56,040 KB
testcase_02 AC 131 ms
55,868 KB
testcase_03 AC 240 ms
59,808 KB
testcase_04 AC 221 ms
57,672 KB
testcase_05 AC 257 ms
59,780 KB
testcase_06 AC 235 ms
59,680 KB
testcase_07 AC 230 ms
59,168 KB
testcase_08 AC 229 ms
59,656 KB
testcase_09 AC 209 ms
59,016 KB
testcase_10 AC 267 ms
60,540 KB
testcase_11 AC 229 ms
59,524 KB
testcase_12 AC 247 ms
60,464 KB
testcase_13 AC 258 ms
60,112 KB
testcase_14 AC 144 ms
55,716 KB
testcase_15 AC 157 ms
56,096 KB
testcase_16 AC 249 ms
60,364 KB
testcase_17 AC 261 ms
60,572 KB
testcase_18 AC 261 ms
60,504 KB
testcase_19 AC 270 ms
60,012 KB
testcase_20 AC 131 ms
55,620 KB
testcase_21 AC 131 ms
55,828 KB
testcase_22 AC 139 ms
55,860 KB
testcase_23 AC 135 ms
56,040 KB
testcase_24 AC 169 ms
55,976 KB
testcase_25 AC 200 ms
56,092 KB
testcase_26 AC 133 ms
55,812 KB
testcase_27 AC 132 ms
55,864 KB
testcase_28 AC 131 ms
55,668 KB
testcase_29 AC 219 ms
59,324 KB
testcase_30 AC 211 ms
58,700 KB
testcase_31 AC 132 ms
55,784 KB
testcase_32 AC 134 ms
56,008 KB
testcase_33 AC 133 ms
56,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
class Yukico5 {
	public static void main(String[] args){
		Scanner stdin = new Scanner(System.in);
		int l = stdin.nextInt();
		int n = stdin.nextInt();
		int[] w = new int[n];
		for(int i=0; i<n; i++) {
			w[i] = stdin.nextInt();
		}
		Arrays.sort(w);
		
		int a=0;
		int i=0;
		while(a<=l && i<n) {
			a = a+w[i];
			i++;
		}
		if(i==n && a<=l) {
			System.out.println(i);
		} else {
			System.out.println(i-1);
		}
	}
}
0