結果

問題 No.5 数字のブロック
ユーザー TwinkleStar74TwinkleStar74
提出日時 2017-09-13 19:40:00
言語 Java19
(openjdk 21)
結果
AC  
実行時間 280 ms / 5,000 ms
コード長 1,086 bytes
コンパイル時間 2,399 ms
コンパイル使用メモリ 71,816 KB
実行使用メモリ 60,812 KB
最終ジャッジ日時 2023-08-11 17:46:39
合計ジャッジ時間 10,751 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 138 ms
55,772 KB
testcase_01 AC 136 ms
56,052 KB
testcase_02 AC 133 ms
55,812 KB
testcase_03 AC 249 ms
59,748 KB
testcase_04 AC 222 ms
59,116 KB
testcase_05 AC 260 ms
60,032 KB
testcase_06 AC 239 ms
59,844 KB
testcase_07 AC 219 ms
59,224 KB
testcase_08 AC 245 ms
60,008 KB
testcase_09 AC 214 ms
58,376 KB
testcase_10 AC 264 ms
60,592 KB
testcase_11 AC 236 ms
59,376 KB
testcase_12 AC 252 ms
59,732 KB
testcase_13 AC 265 ms
59,892 KB
testcase_14 AC 149 ms
55,776 KB
testcase_15 AC 167 ms
55,916 KB
testcase_16 AC 256 ms
60,344 KB
testcase_17 AC 276 ms
60,812 KB
testcase_18 AC 267 ms
60,520 KB
testcase_19 AC 280 ms
60,404 KB
testcase_20 AC 133 ms
55,700 KB
testcase_21 AC 133 ms
55,760 KB
testcase_22 AC 133 ms
55,712 KB
testcase_23 AC 133 ms
55,708 KB
testcase_24 AC 163 ms
56,008 KB
testcase_25 AC 191 ms
55,768 KB
testcase_26 AC 132 ms
55,780 KB
testcase_27 AC 135 ms
56,068 KB
testcase_28 AC 133 ms
55,708 KB
testcase_29 AC 216 ms
58,968 KB
testcase_30 AC 211 ms
58,964 KB
testcase_31 AC 135 ms
55,760 KB
testcase_32 AC 130 ms
55,716 KB
testcase_33 AC 133 ms
55,864 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