結果

問題 No.5 数字のブロック
ユーザー atkrym
提出日時 2016-10-13 12:33:12
言語 Java
(openjdk 23)
結果
AC  
実行時間 269 ms / 5,000 ms
コード長 640 bytes
コンパイル時間 2,091 ms
コンパイル使用メモリ 76,436 KB
実行使用メモリ 59,164 KB
最終ジャッジ日時 2024-11-18 09:54:09
合計ジャッジ時間 9,121 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        int l = sc.nextInt();
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(sc.nextInt());
        }
        
        Collections.sort(list);
        
        int sum = 0;
        int ret = 0;
        for (Integer i : list) {
            sum += i;
            if (sum > l) {
                break;
            }
            ret++;
        }
        
        System.out.println(ret);
    }
}
0