結果

問題 No.5 数字のブロック
ユーザー atkrym
提出日時 2016-10-13 12:30:46
言語 Java
(openjdk 23)
結果
AC  
実行時間 294 ms / 5,000 ms
コード長 641 bytes
コンパイル時間 2,340 ms
コンパイル使用メモリ 76,184 KB
実行使用メモリ 59,180 KB
最終ジャッジ日時 2024-11-18 09:49:21
合計ジャッジ時間 10,049 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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