結果

問題 No.5 数字のブロック
ユーザー koukonkokoukonko
提出日時 2015-12-16 21:23:55
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 829 bytes
コンパイル時間 1,843 ms
コンパイル使用メモリ 73,984 KB
実行使用メモリ 52,472 KB
最終ジャッジ日時 2023-10-14 11:05:27
合計ジャッジ時間 5,417 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
49,464 KB
testcase_01 AC 40 ms
49,340 KB
testcase_02 WA -
testcase_03 AC 89 ms
52,208 KB
testcase_04 AC 68 ms
51,632 KB
testcase_05 AC 90 ms
51,944 KB
testcase_06 AC 76 ms
52,140 KB
testcase_07 AC 68 ms
52,064 KB
testcase_08 AC 74 ms
52,272 KB
testcase_09 AC 56 ms
50,428 KB
testcase_10 AC 93 ms
52,084 KB
testcase_11 AC 69 ms
51,860 KB
testcase_12 AC 90 ms
51,908 KB
testcase_13 AC 81 ms
52,376 KB
testcase_14 AC 42 ms
49,348 KB
testcase_15 AC 44 ms
49,524 KB
testcase_16 AC 92 ms
52,168 KB
testcase_17 AC 103 ms
52,472 KB
testcase_18 AC 98 ms
52,128 KB
testcase_19 AC 93 ms
52,432 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 40 ms
49,272 KB
testcase_24 AC 44 ms
49,248 KB
testcase_25 AC 45 ms
49,364 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 68 ms
51,516 KB
testcase_30 AC 57 ms
50,964 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		BufferedReader read = new BufferedReader(new InputStreamReader(System.in));

		try {
			int L = Integer.parseInt(read.readLine());
			int N = Integer.parseInt(read.readLine());

			String[] box = read.readLine().split(" ");
			int[] w = new int[N];
			for (int i = 0; i < N; ++i) {
				w[i] = Integer.parseInt(box[i]);
			}

			int total = 0, ans = 0;
			for (int i = 0; i < N - 1; ++i) {
				for (int j = i + 1; j < N; ++j) {
					if (w[i] > w[j]) {
						int sw = w[i];
						w[i] = w[j];
						w[j] = sw;
					}
				}
				total += w[i];
				if (total <= L) {
					++ans;
				} else {
					break;
				}

			}
			System.out.println(ans);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
0