結果

問題 No.5 数字のブロック
ユーザー S1hoS1ho
提出日時 2017-02-19 16:22:58
言語 Java21
(openjdk 21)
結果
AC  
実行時間 270 ms / 5,000 ms
コード長 833 bytes
コンパイル時間 4,730 ms
コンパイル使用メモリ 74,108 KB
実行使用メモリ 60,752 KB
最終ジャッジ日時 2023-08-11 17:06:13
合計ジャッジ時間 11,394 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,896 KB
testcase_01 AC 120 ms
55,744 KB
testcase_02 AC 120 ms
55,808 KB
testcase_03 AC 240 ms
59,824 KB
testcase_04 AC 221 ms
60,096 KB
testcase_05 AC 253 ms
60,312 KB
testcase_06 AC 234 ms
60,184 KB
testcase_07 AC 213 ms
59,348 KB
testcase_08 AC 239 ms
59,312 KB
testcase_09 AC 203 ms
58,068 KB
testcase_10 AC 266 ms
60,396 KB
testcase_11 AC 223 ms
59,424 KB
testcase_12 AC 244 ms
59,688 KB
testcase_13 AC 253 ms
59,768 KB
testcase_14 AC 138 ms
55,812 KB
testcase_15 AC 161 ms
55,476 KB
testcase_16 AC 252 ms
60,524 KB
testcase_17 AC 270 ms
60,752 KB
testcase_18 AC 262 ms
60,348 KB
testcase_19 AC 270 ms
60,016 KB
testcase_20 AC 121 ms
55,704 KB
testcase_21 AC 121 ms
56,068 KB
testcase_22 AC 119 ms
55,888 KB
testcase_23 AC 123 ms
55,984 KB
testcase_24 AC 146 ms
55,744 KB
testcase_25 AC 178 ms
56,240 KB
testcase_26 AC 122 ms
55,720 KB
testcase_27 AC 122 ms
56,016 KB
testcase_28 AC 122 ms
55,844 KB
testcase_29 AC 211 ms
59,576 KB
testcase_30 AC 203 ms
58,372 KB
testcase_31 AC 124 ms
55,712 KB
testcase_32 AC 126 ms
55,532 KB
testcase_33 AC 124 ms
56,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Box {

    public static void main(String[] args) {
        
        Scanner scanner = new Scanner(System.in);
        
        int l = scanner.nextInt();
        int n = scanner.nextInt();
        
        ArrayList<Integer> width = new ArrayList();
        
        for(int i=0;i<n;i++){
            width.add(scanner.nextInt());
        }
        
        Collections.sort(width);
        
        int sum = 0;
        int count = 0;
        
        for(int i=0;i<width.size();i++){
            
            sum += width.get(i);
            
            if(sum <= l){
                count++;
            }else{
                break;
            }
               
        }
        
        System.out.println(count);
    }
    
}
0