結果

問題 No.5 数字のブロック
ユーザー crazybbb3crazybbb3
提出日時 2016-12-07 22:08:11
言語 Java21
(openjdk 21)
結果
AC  
実行時間 104 ms / 5,000 ms
コード長 1,946 bytes
コンパイル時間 2,560 ms
コンパイル使用メモリ 74,504 KB
実行使用メモリ 53,468 KB
最終ジャッジ日時 2023-08-11 16:56:37
合計ジャッジ時間 6,172 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,604 KB
testcase_01 AC 45 ms
49,552 KB
testcase_02 AC 44 ms
49,636 KB
testcase_03 AC 88 ms
52,256 KB
testcase_04 AC 72 ms
50,808 KB
testcase_05 AC 99 ms
53,132 KB
testcase_06 AC 85 ms
52,452 KB
testcase_07 AC 70 ms
50,628 KB
testcase_08 AC 86 ms
53,016 KB
testcase_09 AC 73 ms
50,784 KB
testcase_10 AC 90 ms
52,920 KB
testcase_11 AC 73 ms
51,568 KB
testcase_12 AC 89 ms
52,904 KB
testcase_13 AC 100 ms
52,508 KB
testcase_14 AC 47 ms
49,816 KB
testcase_15 AC 48 ms
49,940 KB
testcase_16 AC 98 ms
52,376 KB
testcase_17 AC 93 ms
52,384 KB
testcase_18 AC 100 ms
52,768 KB
testcase_19 AC 104 ms
53,468 KB
testcase_20 AC 45 ms
49,664 KB
testcase_21 AC 45 ms
49,928 KB
testcase_22 AC 45 ms
49,568 KB
testcase_23 AC 46 ms
49,552 KB
testcase_24 AC 49 ms
49,656 KB
testcase_25 AC 52 ms
49,824 KB
testcase_26 AC 46 ms
49,756 KB
testcase_27 AC 45 ms
49,552 KB
testcase_28 AC 46 ms
49,672 KB
testcase_29 AC 72 ms
50,720 KB
testcase_30 AC 74 ms
51,880 KB
testcase_31 AC 48 ms
49,608 KB
testcase_32 AC 46 ms
49,584 KB
testcase_33 AC 45 ms
49,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
        int l = ni();
        int n = ni();
        int[] w = nia(n);
        Arrays.sort(w);

        int sum = 0;
        int ans = 0;
        for (int i = 0; i < n; i++) {
            sum += w[i];
            if (sum > l) {
                break;
            } else {
                ans++;
            }
        }

        out.println(ans);
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}
0