結果

問題 No.5 数字のブロック
ユーザー TwinkleStar74TwinkleStar74
提出日時 2017-09-13 19:34:28
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,070 bytes
コンパイル時間 2,305 ms
コンパイル使用メモリ 74,976 KB
実行使用メモリ 47,756 KB
最終ジャッジ日時 2024-04-25 09:27:44
合計ジャッジ時間 10,190 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
41,372 KB
testcase_01 AC 135 ms
41,168 KB
testcase_02 AC 137 ms
41,132 KB
testcase_03 AC 246 ms
46,368 KB
testcase_04 AC 228 ms
45,768 KB
testcase_05 AC 272 ms
46,960 KB
testcase_06 AC 246 ms
45,972 KB
testcase_07 AC 241 ms
45,604 KB
testcase_08 AC 259 ms
46,768 KB
testcase_09 AC 217 ms
43,820 KB
testcase_10 AC 275 ms
47,452 KB
testcase_11 AC 225 ms
45,740 KB
testcase_12 AC 261 ms
46,380 KB
testcase_13 AC 270 ms
46,944 KB
testcase_14 AC 151 ms
41,624 KB
testcase_15 AC 169 ms
41,564 KB
testcase_16 AC 265 ms
46,324 KB
testcase_17 AC 267 ms
47,576 KB
testcase_18 AC 274 ms
47,096 KB
testcase_19 AC 285 ms
47,756 KB
testcase_20 WA -
testcase_21 AC 134 ms
41,244 KB
testcase_22 AC 134 ms
41,336 KB
testcase_23 AC 136 ms
41,208 KB
testcase_24 AC 161 ms
41,832 KB
testcase_25 AC 187 ms
42,212 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 230 ms
45,576 KB
testcase_30 AC 210 ms
43,848 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

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

       }
}
0