結果

問題 No.5 数字のブロック
ユーザー zimphazimpha
提出日時 2017-03-23 12:04:39
言語 Java21
(openjdk 21)
結果
AC  
実行時間 106 ms / 5,000 ms
コード長 2,091 bytes
コンパイル時間 2,147 ms
コンパイル使用メモリ 74,532 KB
実行使用メモリ 53,092 KB
最終ジャッジ日時 2023-08-11 17:14:24
合計ジャッジ時間 5,825 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
49,444 KB
testcase_01 AC 46 ms
49,396 KB
testcase_02 AC 45 ms
49,488 KB
testcase_03 AC 86 ms
52,712 KB
testcase_04 AC 73 ms
50,852 KB
testcase_05 AC 100 ms
52,288 KB
testcase_06 AC 83 ms
52,460 KB
testcase_07 AC 73 ms
50,572 KB
testcase_08 AC 87 ms
52,764 KB
testcase_09 AC 67 ms
50,752 KB
testcase_10 AC 100 ms
52,348 KB
testcase_11 AC 72 ms
51,648 KB
testcase_12 AC 87 ms
52,432 KB
testcase_13 AC 90 ms
52,408 KB
testcase_14 AC 48 ms
49,608 KB
testcase_15 AC 49 ms
49,412 KB
testcase_16 AC 92 ms
52,692 KB
testcase_17 AC 102 ms
53,092 KB
testcase_18 AC 103 ms
52,568 KB
testcase_19 AC 106 ms
52,440 KB
testcase_20 AC 46 ms
49,584 KB
testcase_21 AC 47 ms
49,272 KB
testcase_22 AC 46 ms
49,452 KB
testcase_23 AC 46 ms
49,316 KB
testcase_24 AC 49 ms
49,516 KB
testcase_25 AC 53 ms
49,420 KB
testcase_26 AC 46 ms
49,596 KB
testcase_27 AC 45 ms
49,544 KB
testcase_28 AC 46 ms
49,480 KB
testcase_29 AC 72 ms
51,636 KB
testcase_30 AC 77 ms
50,768 KB
testcase_31 AC 46 ms
49,820 KB
testcase_32 AC 46 ms
49,460 KB
testcase_33 AC 46 ms
49,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Chiaki.Hoshinomori
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task005 solver = new Task005();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task005 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int L = in.nextInt();
            int n = in.nextInt();
            int[] w = new int[n];
            for (int i = 0; i < n; i++) {
                w[i] = in.nextInt();
            }
            Arrays.sort(w);
            for (int i = 0; i < n; i++) {
                if (w[i] > L) {
                    out.println(i);
                    return;
                }
                L -= w[i];
            }
            out.println(n);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

0