結果

問題 No.617 Nafmo、買い出しに行く
ユーザー denderaKawazudenderaKawazu
提出日時 2018-02-21 16:48:01
言語 Java21
(openjdk 21)
結果
AC  
実行時間 292 ms / 2,000 ms
コード長 1,438 bytes
コンパイル時間 4,451 ms
コンパイル使用メモリ 74,600 KB
実行使用メモリ 87,260 KB
最終ジャッジ日時 2023-10-14 22:33:37
合計ジャッジ時間 7,666 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,940 KB
testcase_01 AC 120 ms
55,528 KB
testcase_02 AC 122 ms
55,664 KB
testcase_03 AC 141 ms
57,708 KB
testcase_04 AC 129 ms
55,988 KB
testcase_05 AC 157 ms
60,868 KB
testcase_06 AC 292 ms
86,348 KB
testcase_07 AC 291 ms
86,472 KB
testcase_08 AC 126 ms
56,020 KB
testcase_09 AC 123 ms
56,064 KB
testcase_10 AC 280 ms
86,956 KB
testcase_11 AC 277 ms
86,724 KB
testcase_12 AC 277 ms
86,952 KB
testcase_13 AC 226 ms
78,592 KB
testcase_14 AC 282 ms
87,260 KB
testcase_15 AC 128 ms
55,700 KB
testcase_16 AC 130 ms
56,000 KB
testcase_17 AC 127 ms
56,164 KB
testcase_18 AC 124 ms
55,980 KB
testcase_19 AC 123 ms
55,580 KB
testcase_20 AC 126 ms
55,316 KB
testcase_21 AC 125 ms
55,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.ArrayList;

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

    static class Task {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            final int n = in.nextInt();
            final int k = in.nextInt();

            ArrayList<Integer> a = new ArrayList<>();
            for (int i = 0; i < n; i++) a.add(in.nextInt());
            ArrayList<Integer> weightSum = new ArrayList<>();
            weightSum.add(0);

            int ans = 0;
            for (int i = 0; i < n; i++) {
                int m = weightSum.size();
                for (int j = 0; j < m; j++) {
                    int newW = weightSum.get(j) + a.get(i);
                    if (newW <= k) {
                        weightSum.add(newW);
                        if (newW > ans) ans = newW;
                    }
                }
            }

            out.println(ans);
        }

    }
}

0