結果

問題 No.5 数字のブロック
ユーザー barrett114514barrett114514
提出日時 2017-07-21 23:46:58
言語 Java21
(openjdk 21)
結果
AC  
実行時間 271 ms / 5,000 ms
コード長 466 bytes
コンパイル時間 3,609 ms
コンパイル使用メモリ 74,812 KB
実行使用メモリ 47,604 KB
最終ジャッジ日時 2024-04-29 09:16:05
合計ジャッジ時間 11,295 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
41,080 KB
testcase_01 AC 129 ms
41,156 KB
testcase_02 AC 123 ms
41,276 KB
testcase_03 AC 240 ms
46,484 KB
testcase_04 AC 221 ms
45,568 KB
testcase_05 AC 252 ms
46,284 KB
testcase_06 AC 235 ms
46,252 KB
testcase_07 AC 222 ms
45,704 KB
testcase_08 AC 239 ms
46,644 KB
testcase_09 AC 198 ms
43,460 KB
testcase_10 AC 250 ms
47,032 KB
testcase_11 AC 221 ms
46,252 KB
testcase_12 AC 246 ms
46,664 KB
testcase_13 AC 255 ms
46,892 KB
testcase_14 AC 142 ms
41,372 KB
testcase_15 AC 163 ms
42,008 KB
testcase_16 AC 254 ms
46,440 KB
testcase_17 AC 264 ms
47,604 KB
testcase_18 AC 268 ms
47,540 KB
testcase_19 AC 271 ms
47,560 KB
testcase_20 AC 127 ms
41,140 KB
testcase_21 AC 126 ms
41,252 KB
testcase_22 AC 116 ms
40,024 KB
testcase_23 AC 126 ms
41,320 KB
testcase_24 AC 161 ms
41,544 KB
testcase_25 AC 174 ms
41,804 KB
testcase_26 AC 134 ms
41,452 KB
testcase_27 AC 115 ms
40,088 KB
testcase_28 AC 127 ms
41,228 KB
testcase_29 AC 213 ms
45,448 KB
testcase_30 AC 201 ms
43,548 KB
testcase_31 AC 128 ms
41,096 KB
testcase_32 AC 128 ms
41,248 KB
testcase_33 AC 127 ms
41,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class NumberBlocks {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int L = sc.nextInt();
		int N = sc.nextInt();
		int W[] = new int[N];
		
		for(int i = 0;i < N; i++){
			W[i] = sc.nextInt();
		}
		Arrays.sort(W);
		
		int ans = 0;
		
		for(int i = 0;i < N;i++){
			L -= W[i];

			if(L >= 0){
				ans ++;
			}else{
				break;
			}
		}
		System.out.println(ans);
	}

}
0