結果

問題 No.5 数字のブロック
ユーザー hj5ln8kbDM8t2fF
提出日時 2019-06-16 15:43:58
言語 Java
(openjdk 23)
結果
AC  
実行時間 281 ms / 5,000 ms
コード長 1,102 bytes
コンパイル時間 2,092 ms
コンパイル使用メモリ 75,416 KB
実行使用メモリ 47,960 KB
最終ジャッジ日時 2024-11-24 03:58:08
合計ジャッジ時間 9,564 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc1 = new Scanner(System.in);
//        Scanner sc2 = new Scanner(System.in);
//        Scanner sc3 = new Scanner(System.in);
        List <Integer> W = new ArrayList<Integer>();

        //大きな箱の幅
        int L = sc1.nextInt();
        
        //ブロックの数
//        int N = sc2.nextInt();
        int N = sc1.nextInt();
        
        //各ブロックの幅を格納
        for(int i=0;i<N;i++ ){
//            int input = sc3.nextInt();
            int input = sc1.nextInt();
            W.add(input);
        }
        
        //昇順でsort
        Collections.sort(W);
        
        //大きな箱の中に、小さい箱を入れていく
        int total = 0;
        int kosu = 0;
        for(int j=0;j<N;j++){
            int num = W.get(j);
            total = total + num;
            if(total > L){
                break;
            }
            else{
                kosu = j + 1;
            }
        }
        System.out.println(kosu);
        
    }
}
0