結果

問題 No.5 数字のブロック
ユーザー YOSHIYOSHI
提出日時 2021-02-17 10:15:00
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 775 bytes
コンパイル時間 5,008 ms
コンパイル使用メモリ 72,564 KB
実行使用メモリ 60,400 KB
最終ジャッジ日時 2023-10-11 21:44:31
合計ジャッジ時間 12,126 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,620 KB
testcase_01 AC 122 ms
55,872 KB
testcase_02 AC 122 ms
55,688 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 125 ms
55,356 KB
testcase_21 AC 125 ms
55,828 KB
testcase_22 AC 126 ms
55,952 KB
testcase_23 AC 124 ms
55,756 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 124 ms
55,308 KB
testcase_27 AC 123 ms
55,740 KB
testcase_28 AC 122 ms
55,720 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 124 ms
56,144 KB
testcase_32 AC 124 ms
55,840 KB
testcase_33 AC 123 ms
55,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class No00000005_Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int lineCnt = 0;
		int l = 0;
		int n = 0;
		String[] wi = null;

		while(scan.hasNextLine()) {
			lineCnt++;
			if(lineCnt == 1) {
				l = Integer.parseInt(scan.nextLine());
			} else if(lineCnt == 2) {
				n =  Integer.parseInt(scan.nextLine());
			} else if(lineCnt == 3) {
				wi = scan.nextLine().split(" ");
			}
			if(lineCnt == 3) {
				break;
			}
		}

		Arrays.sort(wi);

		int cnt = 0;
		int sum = 0;
		for(int i = 0; i < n; i++) {
			int temp = Integer.parseInt(wi[i]);
			if(sum + temp > l) {
				break;
			}
			sum += temp;
			cnt++;
		}

		System.out.println(cnt);

		scan.close();

	}

}
0