結果

問題 No.5 数字のブロック
ユーザー koukonkokoukonko
提出日時 2015-12-07 11:01:39
言語 Java21
(openjdk 21)
結果
AC  
実行時間 234 ms / 5,000 ms
コード長 868 bytes
コンパイル時間 2,097 ms
コンパイル使用メモリ 76,320 KB
実行使用メモリ 39,648 KB
最終ジャッジ日時 2024-04-29 06:41:39
合計ジャッジ時間 6,737 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
36,568 KB
testcase_01 AC 50 ms
36,848 KB
testcase_02 AC 50 ms
36,984 KB
testcase_03 AC 141 ms
38,888 KB
testcase_04 AC 109 ms
38,532 KB
testcase_05 AC 187 ms
39,228 KB
testcase_06 AC 123 ms
38,764 KB
testcase_07 AC 105 ms
38,272 KB
testcase_08 AC 139 ms
38,640 KB
testcase_09 AC 102 ms
38,936 KB
testcase_10 AC 204 ms
38,864 KB
testcase_11 AC 121 ms
39,648 KB
testcase_12 AC 156 ms
39,156 KB
testcase_13 AC 185 ms
38,964 KB
testcase_14 AC 53 ms
37,012 KB
testcase_15 AC 54 ms
36,736 KB
testcase_16 AC 189 ms
39,076 KB
testcase_17 AC 225 ms
39,376 KB
testcase_18 AC 213 ms
39,288 KB
testcase_19 AC 234 ms
39,540 KB
testcase_20 AC 49 ms
36,800 KB
testcase_21 AC 51 ms
36,976 KB
testcase_22 AC 50 ms
36,872 KB
testcase_23 AC 51 ms
36,744 KB
testcase_24 AC 55 ms
36,984 KB
testcase_25 AC 57 ms
36,804 KB
testcase_26 AC 51 ms
36,852 KB
testcase_27 AC 51 ms
36,652 KB
testcase_28 AC 51 ms
36,424 KB
testcase_29 AC 108 ms
38,208 KB
testcase_30 AC 107 ms
39,308 KB
testcase_31 AC 50 ms
36,564 KB
testcase_32 AC 51 ms
36,928 KB
testcase_33 AC 51 ms
36,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

		try {
			int L = Integer.parseInt(buff.readLine());
			int N = Integer.parseInt(buff.readLine());
			int[] box = new int[N];
			String[] str = buff.readLine().split(" ");

			for (int i = 0; i < N; ++i) {
				box[i] = Integer.parseInt(str[i]);
				for (int j = 0; j < i; ++j) {
					if (box[i] < box[j]) {
						int w = box[i];
						box[i] = box[j];
						box[j] = w;
					}
				}
			}
			int ans = 0;
			int sum = 0;
			for (int i = 0; i < N; ++i) {
				sum += box[i];
				if (sum > L) {
					break;
				}
				++ans;
			}

			System.out.println(ans);
		} catch (NumberFormatException e) {

		} catch (IOException e) {

		}
	}
}
0