結果

問題 No.5 数字のブロック
ユーザー koukonkokoukonko
提出日時 2015-12-16 21:26:03
言語 Java21
(openjdk 21)
結果
AC  
実行時間 345 ms / 5,000 ms
コード長 887 bytes
コンパイル時間 2,082 ms
コンパイル使用メモリ 75,552 KB
実行使用メモリ 39,672 KB
最終ジャッジ日時 2024-04-29 06:41:53
合計ジャッジ時間 7,438 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
36,840 KB
testcase_01 AC 52 ms
36,436 KB
testcase_02 AC 52 ms
36,876 KB
testcase_03 AC 194 ms
38,900 KB
testcase_04 AC 116 ms
39,672 KB
testcase_05 AC 239 ms
38,936 KB
testcase_06 AC 157 ms
39,168 KB
testcase_07 AC 133 ms
38,356 KB
testcase_08 AC 170 ms
38,932 KB
testcase_09 AC 112 ms
39,180 KB
testcase_10 AC 245 ms
39,124 KB
testcase_11 AC 125 ms
38,344 KB
testcase_12 AC 198 ms
38,764 KB
testcase_13 AC 247 ms
39,372 KB
testcase_14 AC 52 ms
36,728 KB
testcase_15 AC 53 ms
36,600 KB
testcase_16 AC 273 ms
39,164 KB
testcase_17 AC 345 ms
39,404 KB
testcase_18 AC 264 ms
39,368 KB
testcase_19 AC 337 ms
39,396 KB
testcase_20 AC 51 ms
36,708 KB
testcase_21 AC 52 ms
36,796 KB
testcase_22 AC 51 ms
36,480 KB
testcase_23 AC 53 ms
36,684 KB
testcase_24 AC 54 ms
37,004 KB
testcase_25 AC 58 ms
36,672 KB
testcase_26 AC 51 ms
36,708 KB
testcase_27 AC 52 ms
36,840 KB
testcase_28 AC 51 ms
36,640 KB
testcase_29 AC 108 ms
38,776 KB
testcase_30 AC 92 ms
38,520 KB
testcase_31 AC 51 ms
36,432 KB
testcase_32 AC 50 ms
36,976 KB
testcase_33 AC 51 ms
36,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

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;
					}
				}
			}
			for (int i = 0; i < N; ++i) {
				total += w[i];
				if (total <= L) {
					++ans;
				} else {
					break;
				}

			}
			System.out.println(ans);

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