結果

問題 No.5 数字のブロック
ユーザー barrett114514barrett114514
提出日時 2017-07-21 23:46:58
言語 Java21
(openjdk 21)
結果
AC  
実行時間 268 ms / 5,000 ms
コード長 466 bytes
コンパイル時間 5,540 ms
コンパイル使用メモリ 73,256 KB
実行使用メモリ 61,108 KB
最終ジャッジ日時 2023-08-11 17:39:11
合計ジャッジ時間 13,259 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,512 KB
testcase_01 AC 125 ms
56,132 KB
testcase_02 AC 125 ms
55,640 KB
testcase_03 AC 231 ms
61,108 KB
testcase_04 AC 217 ms
59,472 KB
testcase_05 AC 254 ms
60,220 KB
testcase_06 AC 219 ms
59,180 KB
testcase_07 AC 221 ms
59,144 KB
testcase_08 AC 233 ms
58,932 KB
testcase_09 AC 199 ms
57,960 KB
testcase_10 AC 256 ms
60,352 KB
testcase_11 AC 219 ms
59,480 KB
testcase_12 AC 237 ms
59,728 KB
testcase_13 AC 251 ms
60,320 KB
testcase_14 AC 143 ms
55,732 KB
testcase_15 AC 155 ms
55,820 KB
testcase_16 AC 257 ms
60,364 KB
testcase_17 AC 268 ms
61,068 KB
testcase_18 AC 260 ms
60,860 KB
testcase_19 AC 267 ms
60,704 KB
testcase_20 AC 128 ms
55,716 KB
testcase_21 AC 128 ms
55,716 KB
testcase_22 AC 127 ms
55,696 KB
testcase_23 AC 129 ms
55,712 KB
testcase_24 AC 155 ms
55,704 KB
testcase_25 AC 184 ms
56,332 KB
testcase_26 AC 126 ms
55,516 KB
testcase_27 AC 125 ms
55,448 KB
testcase_28 AC 126 ms
55,952 KB
testcase_29 AC 218 ms
59,488 KB
testcase_30 AC 201 ms
58,436 KB
testcase_31 AC 127 ms
55,648 KB
testcase_32 AC 127 ms
56,024 KB
testcase_33 AC 126 ms
55,704 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