結果

問題 No.5 数字のブロック
ユーザー Naoyk1212Naoyk1212
提出日時 2015-07-24 15:34:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 249 ms / 5,000 ms
コード長 499 bytes
コンパイル時間 2,081 ms
コンパイル使用メモリ 74,440 KB
実行使用メモリ 47,924 KB
最終ジャッジ日時 2024-04-29 01:07:07
合計ジャッジ時間 8,425 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 100 ms
39,932 KB
testcase_01 AC 102 ms
41,352 KB
testcase_02 AC 112 ms
41,112 KB
testcase_03 AC 211 ms
46,272 KB
testcase_04 AC 189 ms
45,572 KB
testcase_05 AC 224 ms
47,340 KB
testcase_06 AC 206 ms
46,152 KB
testcase_07 AC 196 ms
45,744 KB
testcase_08 AC 205 ms
46,596 KB
testcase_09 AC 176 ms
43,200 KB
testcase_10 AC 229 ms
47,200 KB
testcase_11 AC 204 ms
46,112 KB
testcase_12 AC 220 ms
46,604 KB
testcase_13 AC 227 ms
46,740 KB
testcase_14 AC 123 ms
41,808 KB
testcase_15 AC 146 ms
41,820 KB
testcase_16 AC 220 ms
46,864 KB
testcase_17 AC 236 ms
47,104 KB
testcase_18 AC 238 ms
47,748 KB
testcase_19 AC 249 ms
47,924 KB
testcase_20 AC 117 ms
41,148 KB
testcase_21 AC 112 ms
41,348 KB
testcase_22 AC 104 ms
41,144 KB
testcase_23 AC 111 ms
40,220 KB
testcase_24 AC 134 ms
41,696 KB
testcase_25 AC 157 ms
42,296 KB
testcase_26 AC 112 ms
41,444 KB
testcase_27 AC 101 ms
41,172 KB
testcase_28 AC 106 ms
41,516 KB
testcase_29 AC 192 ms
45,772 KB
testcase_30 AC 181 ms
43,604 KB
testcase_31 AC 114 ms
41,220 KB
testcase_32 AC 113 ms
41,104 KB
testcase_33 AC 111 ms
41,216 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