結果

問題 No.5 数字のブロック
コンテスト
ユーザー jonki324
提出日時 2018-06-04 11:08:03
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 171 ms / 5,000 ms
コード長 603 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,656 ms
コンパイル使用メモリ 82,244 KB
実行使用メモリ 51,348 KB
最終ジャッジ日時 2026-05-13 00:16:34
合計ジャッジ時間 6,404 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.util.Arrays;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int l = scan.nextInt();
        int n = scan.nextInt();
        int[] w = new int[n];
        for (int i = 0; i < n; i++) {
            w[i] = scan.nextInt();
        }
        Arrays.sort(w);
        int cnt = 0;
        for (int v : w) {
            l -= v;
            if (l < 0) {
                break;
            } else {
                cnt++;
            }
        }
        System.out.println(cnt);
        scan.close();
    }
}
0