結果

問題 No.5 数字のブロック
ユーザー masuyuumasuyuu
提出日時 2020-09-17 21:26:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 284 ms / 5,000 ms
コード長 542 bytes
コンパイル時間 2,222 ms
コンパイル使用メモリ 73,300 KB
実行使用メモリ 62,032 KB
最終ジャッジ日時 2023-09-04 07:38:05
合計ジャッジ時間 10,146 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,504 KB
testcase_01 AC 124 ms
56,140 KB
testcase_02 AC 121 ms
55,416 KB
testcase_03 AC 231 ms
60,512 KB
testcase_04 AC 216 ms
59,884 KB
testcase_05 AC 242 ms
60,800 KB
testcase_06 AC 218 ms
57,696 KB
testcase_07 AC 207 ms
59,348 KB
testcase_08 AC 220 ms
59,352 KB
testcase_09 AC 189 ms
58,368 KB
testcase_10 AC 247 ms
60,596 KB
testcase_11 AC 198 ms
59,144 KB
testcase_12 AC 234 ms
59,416 KB
testcase_13 AC 236 ms
60,308 KB
testcase_14 AC 138 ms
55,692 KB
testcase_15 AC 154 ms
55,664 KB
testcase_16 AC 261 ms
60,180 KB
testcase_17 AC 278 ms
60,624 KB
testcase_18 AC 280 ms
60,276 KB
testcase_19 AC 284 ms
62,032 KB
testcase_20 AC 127 ms
55,940 KB
testcase_21 AC 127 ms
55,772 KB
testcase_22 AC 126 ms
56,044 KB
testcase_23 AC 125 ms
55,980 KB
testcase_24 AC 156 ms
56,140 KB
testcase_25 AC 189 ms
56,028 KB
testcase_26 AC 124 ms
55,880 KB
testcase_27 AC 127 ms
55,504 KB
testcase_28 AC 126 ms
55,768 KB
testcase_29 AC 229 ms
59,000 KB
testcase_30 AC 212 ms
58,356 KB
testcase_31 AC 128 ms
55,812 KB
testcase_32 AC 127 ms
55,908 KB
testcase_33 AC 127 ms
56,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int c = sc.nextInt();
		int h = sc.nextInt();
		List<Integer> a = new ArrayList<>();
		for(int i=0;i<h;i++) {
			int x = sc.nextInt();
			a.add(x);
		}
		Collections.sort(a);
		int sum =0;
		int cnt=0;
		int g=0;
		while(sum<c && cnt!=h) {
			sum+=a.get(g);
			if(sum<=c) {
				cnt++;
			}
			g++;
		}
		System.out.println(cnt);
	}
}
0