結果

問題 No.5 数字のブロック
ユーザー ajukinkinajukinkin
提出日時 2016-07-07 16:02:52
言語 Java21
(openjdk 21)
結果
AC  
実行時間 109 ms / 5,000 ms
コード長 1,227 bytes
コンパイル時間 3,404 ms
コンパイル使用メモリ 74,752 KB
実行使用メモリ 40,120 KB
最終ジャッジ日時 2024-04-29 07:24:07
合計ジャッジ時間 6,798 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
37,020 KB
testcase_01 AC 54 ms
36,892 KB
testcase_02 AC 52 ms
37,100 KB
testcase_03 AC 85 ms
38,916 KB
testcase_04 AC 84 ms
38,292 KB
testcase_05 AC 102 ms
39,688 KB
testcase_06 AC 86 ms
39,092 KB
testcase_07 AC 84 ms
38,220 KB
testcase_08 AC 96 ms
38,964 KB
testcase_09 AC 60 ms
37,304 KB
testcase_10 AC 100 ms
39,548 KB
testcase_11 AC 84 ms
38,572 KB
testcase_12 AC 86 ms
38,744 KB
testcase_13 AC 92 ms
39,728 KB
testcase_14 AC 54 ms
36,812 KB
testcase_15 AC 52 ms
37,000 KB
testcase_16 AC 96 ms
39,572 KB
testcase_17 AC 100 ms
40,120 KB
testcase_18 AC 104 ms
40,104 KB
testcase_19 AC 109 ms
39,856 KB
testcase_20 AC 52 ms
37,288 KB
testcase_21 AC 51 ms
37,056 KB
testcase_22 AC 53 ms
36,800 KB
testcase_23 AC 51 ms
36,868 KB
testcase_24 AC 52 ms
37,008 KB
testcase_25 AC 54 ms
37,076 KB
testcase_26 AC 51 ms
37,180 KB
testcase_27 AC 51 ms
36,816 KB
testcase_28 AC 52 ms
37,280 KB
testcase_29 AC 68 ms
38,300 KB
testcase_30 AC 62 ms
37,404 KB
testcase_31 AC 54 ms
37,224 KB
testcase_32 AC 55 ms
36,812 KB
testcase_33 AC 52 ms
36,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main01 {
  public static void main(String[] args) {
    try {
      InputStreamReader inputStreamReader = new InputStreamReader(System.in);
      BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

      String strBoxLength = bufferedReader.readLine();
      int boxLength = Integer.parseInt(strBoxLength);
      String strBlockNum = bufferedReader.readLine();
      int blockNum = Integer.parseInt(strBlockNum);
      String strBoxsWidth = bufferedReader.readLine();
      String[] strBoxWidths = strBoxsWidth.split(" ");
      int[] boxWidths = new int[strBoxWidths.length];
      for (int i = 0; i < blockNum; i++) {
        boxWidths[i] = Integer.parseInt(strBoxWidths[i]);
      }
      
      // ソート
      Arrays.sort(boxWidths);
      
      int width = 0; // 幅
      int boxNum = 1; // 箱の個数
      for (int i = 0; i < strBoxWidths.length; i++) {
          if (width + boxWidths[i] > boxLength) {
            break;
          }
          boxNum = i + 1;
          width += boxWidths[i];
      }
      
      // 結果出力
      System.out.println(boxNum);
    } catch (Throwable th) {
      th.printStackTrace();
    }
   }
}
0