結果

問題 No.5 数字のブロック
ユーザー spaciaspacia
提出日時 2015-12-15 20:47:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 92 ms / 5,000 ms
コード長 768 bytes
コンパイル時間 2,562 ms
コンパイル使用メモリ 71,852 KB
実行使用メモリ 53,464 KB
最終ジャッジ日時 2023-08-11 14:25:02
合計ジャッジ時間 5,231 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
49,420 KB
testcase_01 AC 39 ms
49,344 KB
testcase_02 AC 40 ms
49,468 KB
testcase_03 AC 71 ms
52,040 KB
testcase_04 AC 61 ms
52,100 KB
testcase_05 AC 83 ms
52,800 KB
testcase_06 AC 80 ms
52,500 KB
testcase_07 AC 65 ms
51,324 KB
testcase_08 AC 83 ms
52,804 KB
testcase_09 AC 54 ms
52,600 KB
testcase_10 AC 86 ms
52,568 KB
testcase_11 AC 61 ms
51,868 KB
testcase_12 AC 73 ms
53,464 KB
testcase_13 AC 87 ms
52,924 KB
testcase_14 AC 42 ms
49,340 KB
testcase_15 AC 43 ms
49,444 KB
testcase_16 AC 86 ms
52,728 KB
testcase_17 AC 77 ms
52,852 KB
testcase_18 AC 87 ms
52,572 KB
testcase_19 AC 92 ms
53,196 KB
testcase_20 AC 42 ms
49,420 KB
testcase_21 AC 42 ms
49,636 KB
testcase_22 AC 42 ms
49,496 KB
testcase_23 AC 42 ms
49,404 KB
testcase_24 AC 44 ms
49,260 KB
testcase_25 AC 47 ms
49,456 KB
testcase_26 AC 42 ms
49,500 KB
testcase_27 AC 45 ms
49,344 KB
testcase_28 AC 42 ms
49,488 KB
testcase_29 AC 59 ms
51,628 KB
testcase_30 AC 55 ms
51,420 KB
testcase_31 AC 42 ms
49,384 KB
testcase_32 AC 41 ms
49,416 KB
testcase_33 AC 42 ms
49,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

class Main5 {
	
	public static int solve (int[] wides , int max) {
		int ret = 0 , sum = 0;
		for (int i = 0; i < wides.length; i++) {
			if (sum + wides[i] <= max) {
				sum += wides[i];
				ret++;
			} else {
				break;
			}
		}
		return ret;
	}
	
	public static void main (String[] args) throws IOException {
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
			
		int max = Integer.parseInt(br.readLine());
		int blockCnt = Integer.parseInt(br.readLine());
		int[] wides = new int[blockCnt];
		
		String[] str = br.readLine().split(" ");
		for (int i = 0; i < blockCnt; i++) {
			wides[i] = Integer.parseInt(str[i]);
		}
		
		Arrays.sort(wides);
		
		System.out.println(solve(wides , max));
	}
}
0