結果

問題 No.5 数字のブロック
ユーザー ryosuke0825ryosuke0825
提出日時 2018-04-04 02:00:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 305 ms / 5,000 ms
コード長 556 bytes
コンパイル時間 2,438 ms
コンパイル使用メモリ 81,112 KB
実行使用メモリ 48,004 KB
最終ジャッジ日時 2024-04-29 09:44:18
合計ジャッジ時間 10,166 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
40,908 KB
testcase_01 AC 139 ms
41,492 KB
testcase_02 AC 139 ms
41,240 KB
testcase_03 AC 260 ms
46,640 KB
testcase_04 AC 236 ms
45,852 KB
testcase_05 AC 272 ms
47,024 KB
testcase_06 AC 244 ms
45,824 KB
testcase_07 AC 239 ms
45,876 KB
testcase_08 AC 249 ms
46,240 KB
testcase_09 AC 211 ms
43,472 KB
testcase_10 AC 281 ms
48,004 KB
testcase_11 AC 249 ms
45,992 KB
testcase_12 AC 263 ms
46,876 KB
testcase_13 AC 265 ms
46,508 KB
testcase_14 AC 143 ms
41,448 KB
testcase_15 AC 164 ms
41,332 KB
testcase_16 AC 265 ms
47,260 KB
testcase_17 AC 292 ms
47,600 KB
testcase_18 AC 295 ms
47,448 KB
testcase_19 AC 305 ms
47,932 KB
testcase_20 AC 134 ms
41,296 KB
testcase_21 AC 136 ms
40,880 KB
testcase_22 AC 132 ms
40,868 KB
testcase_23 AC 135 ms
41,220 KB
testcase_24 AC 168 ms
41,960 KB
testcase_25 AC 203 ms
41,836 KB
testcase_26 AC 137 ms
40,976 KB
testcase_27 AC 134 ms
41,496 KB
testcase_28 AC 121 ms
40,448 KB
testcase_29 AC 238 ms
45,552 KB
testcase_30 AC 219 ms
43,680 KB
testcase_31 AC 133 ms
41,456 KB
testcase_32 AC 134 ms
41,120 KB
testcase_33 AC 129 ms
41,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder1_0;

import java.util.ArrayList;
import java.util.Collections;
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();

		ArrayList<Integer> w = new ArrayList<Integer>();
		for(int i = 0; i < N; i++) {
			w.add(sc.nextInt());
		}

		Collections.sort(w);

		int sum = 0;
		int count =0;
		for(int i : w) {
			if(sum+i<= L)  {
				sum +=i;
				count++;
			}else {
				break;
			}
		}

		System.out.println(count);

	}
}
0