結果

問題 No.5 数字のブロック
ユーザー TwinkleStar74TwinkleStar74
提出日時 2017-09-13 19:40:00
言語 Java21
(openjdk 21)
結果
AC  
実行時間 243 ms / 5,000 ms
コード長 1,086 bytes
コンパイル時間 1,756 ms
コンパイル使用メモリ 75,748 KB
実行使用メモリ 47,888 KB
最終ジャッジ日時 2024-04-29 09:21:45
合計ジャッジ時間 8,212 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
41,400 KB
testcase_01 AC 107 ms
41,352 KB
testcase_02 AC 106 ms
41,220 KB
testcase_03 AC 213 ms
46,424 KB
testcase_04 AC 193 ms
45,552 KB
testcase_05 AC 217 ms
47,288 KB
testcase_06 AC 208 ms
46,316 KB
testcase_07 AC 201 ms
45,612 KB
testcase_08 AC 203 ms
46,604 KB
testcase_09 AC 172 ms
43,672 KB
testcase_10 AC 222 ms
47,684 KB
testcase_11 AC 192 ms
46,284 KB
testcase_12 AC 215 ms
46,696 KB
testcase_13 AC 220 ms
47,236 KB
testcase_14 AC 124 ms
41,348 KB
testcase_15 AC 130 ms
41,924 KB
testcase_16 AC 216 ms
46,916 KB
testcase_17 AC 243 ms
47,472 KB
testcase_18 AC 221 ms
47,628 KB
testcase_19 AC 240 ms
47,888 KB
testcase_20 AC 107 ms
41,524 KB
testcase_21 AC 108 ms
41,056 KB
testcase_22 AC 106 ms
41,376 KB
testcase_23 AC 115 ms
41,592 KB
testcase_24 AC 144 ms
41,640 KB
testcase_25 AC 158 ms
41,896 KB
testcase_26 AC 110 ms
41,116 KB
testcase_27 AC 103 ms
41,332 KB
testcase_28 AC 112 ms
41,808 KB
testcase_29 AC 188 ms
45,596 KB
testcase_30 AC 179 ms
43,912 KB
testcase_31 AC 103 ms
41,496 KB
testcase_32 AC 117 ms
41,524 KB
testcase_33 AC 102 ms
41,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.Arrays;

class No5{
       public static void main(String[] args){
              Scanner sc = new Scanner(System.in);
              int hw= sc.nextInt();  
              int n = sc.nextInt();
              int bw[] = new int[n];

              for ( int i=0; i<n; i++ ){   //配列bw[n]に入れていく
                    bw[i] = sc.nextInt();
              }

              Arrays.sort(bw);   //昇順にソート

              int totalBw= 0;
              int count =0;
              for ( int k=0; k<n; k++ ){   //変数にbw[0]から足していく
                    if ( totalBw < hw ){
                    totalBw += bw[k];
                    count++;
                    }
              }

             if ( totalBw < hw || totalBw == hw ){  //最後に足して箱の幅一致ならそのまま出力
             System.out.println ( count );
             }
             if ( totalBw > hw ){   //最後に足して箱の幅を越えれば-1して出力
             System.out.println ( count - 1 );
             }

       }
}
0