結果

問題 No.5 数字のブロック
ユーザー doyazaki012doyazaki012
提出日時 2015-04-24 17:47:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 273 ms / 5,000 ms
コード長 442 bytes
コンパイル時間 2,181 ms
コンパイル使用メモリ 74,756 KB
実行使用メモリ 47,784 KB
最終ジャッジ日時 2024-04-29 00:51:54
合計ジャッジ時間 9,552 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
41,140 KB
testcase_01 AC 119 ms
39,924 KB
testcase_02 AC 117 ms
40,016 KB
testcase_03 AC 248 ms
46,748 KB
testcase_04 AC 214 ms
45,712 KB
testcase_05 AC 256 ms
47,288 KB
testcase_06 AC 229 ms
46,304 KB
testcase_07 AC 225 ms
45,616 KB
testcase_08 AC 236 ms
46,992 KB
testcase_09 AC 204 ms
43,572 KB
testcase_10 AC 257 ms
47,544 KB
testcase_11 AC 228 ms
45,964 KB
testcase_12 AC 243 ms
46,580 KB
testcase_13 AC 256 ms
46,696 KB
testcase_14 AC 145 ms
41,400 KB
testcase_15 AC 170 ms
41,892 KB
testcase_16 AC 251 ms
46,336 KB
testcase_17 AC 257 ms
47,476 KB
testcase_18 AC 271 ms
47,616 KB
testcase_19 AC 273 ms
47,784 KB
testcase_20 AC 128 ms
41,356 KB
testcase_21 AC 114 ms
39,868 KB
testcase_22 AC 127 ms
41,292 KB
testcase_23 AC 128 ms
41,256 KB
testcase_24 AC 162 ms
41,764 KB
testcase_25 AC 179 ms
41,884 KB
testcase_26 AC 134 ms
41,432 KB
testcase_27 AC 120 ms
39,880 KB
testcase_28 AC 130 ms
40,956 KB
testcase_29 AC 223 ms
45,588 KB
testcase_30 AC 207 ms
43,820 KB
testcase_31 AC 115 ms
40,000 KB
testcase_32 AC 129 ms
40,940 KB
testcase_33 AC 116 ms
40,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class Yuki5{
	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 k=0;
		int sum = 0;
		while(sum<=l){
			sum+=w[k];
			k++;
			if(k==n&&sum<=l){
				k++;
				break;
			}else if(k==n)
				break;
		}
		System.out.println(k-1);
	}
}
0