結果

問題 No.5 数字のブロック
ユーザー Naoyk1212Naoyk1212
提出日時 2015-07-24 15:34:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 252 ms / 5,000 ms
コード長 499 bytes
コンパイル時間 3,973 ms
コンパイル使用メモリ 72,872 KB
実行使用メモリ 60,684 KB
最終ジャッジ日時 2023-08-11 08:34:27
合計ジャッジ時間 11,936 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
56,196 KB
testcase_01 AC 123 ms
55,492 KB
testcase_02 AC 123 ms
55,924 KB
testcase_03 AC 218 ms
59,872 KB
testcase_04 AC 209 ms
59,208 KB
testcase_05 AC 239 ms
60,044 KB
testcase_06 AC 221 ms
60,184 KB
testcase_07 AC 214 ms
59,056 KB
testcase_08 AC 218 ms
59,216 KB
testcase_09 AC 194 ms
59,020 KB
testcase_10 AC 238 ms
59,692 KB
testcase_11 AC 214 ms
57,448 KB
testcase_12 AC 236 ms
60,448 KB
testcase_13 AC 238 ms
58,076 KB
testcase_14 AC 137 ms
55,644 KB
testcase_15 AC 151 ms
55,684 KB
testcase_16 AC 239 ms
59,996 KB
testcase_17 AC 251 ms
60,312 KB
testcase_18 AC 249 ms
60,684 KB
testcase_19 AC 252 ms
60,496 KB
testcase_20 AC 121 ms
55,784 KB
testcase_21 AC 120 ms
55,736 KB
testcase_22 AC 120 ms
55,600 KB
testcase_23 AC 120 ms
55,504 KB
testcase_24 AC 145 ms
56,156 KB
testcase_25 AC 175 ms
56,036 KB
testcase_26 AC 119 ms
56,032 KB
testcase_27 AC 123 ms
56,192 KB
testcase_28 AC 122 ms
55,956 KB
testcase_29 AC 212 ms
57,076 KB
testcase_30 AC 191 ms
58,832 KB
testcase_31 AC 120 ms
55,992 KB
testcase_32 AC 121 ms
56,028 KB
testcase_33 AC 121 ms
55,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int l = sc.nextInt();
		int n = sc.nextInt();
		int[] N = new int[n];
		int ans = 0;

		for(int i = 0; i < n; i++){
			N[i] = sc.nextInt();
		}

		Arrays.sort(N);

		int i = 0;
		while(l >= ans){
			ans += N[i];
			i++;
			if(i == n && ans <= l){
				i++;
				break;
			}else if(i == n){
				break;
			}
		}
		System.out.println(i - 1);
	}

}
0