結果

問題 No.617 Nafmo、買い出しに行く
ユーザー denderaKawazudenderaKawazu
提出日時 2018-02-21 16:43:39
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,170 ms / 2,000 ms
コード長 1,412 bytes
コンパイル時間 2,094 ms
コンパイル使用メモリ 76,324 KB
実行使用メモリ 90,612 KB
最終ジャッジ日時 2023-10-14 14:18:03
合計ジャッジ時間 11,252 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,520 KB
testcase_01 AC 120 ms
56,092 KB
testcase_02 AC 124 ms
56,336 KB
testcase_03 AC 235 ms
60,584 KB
testcase_04 AC 121 ms
55,940 KB
testcase_05 AC 290 ms
63,176 KB
testcase_06 AC 456 ms
89,032 KB
testcase_07 AC 436 ms
88,964 KB
testcase_08 AC 124 ms
55,676 KB
testcase_09 AC 125 ms
56,368 KB
testcase_10 AC 812 ms
89,512 KB
testcase_11 AC 846 ms
90,104 KB
testcase_12 AC 1,170 ms
90,612 KB
testcase_13 AC 837 ms
89,748 KB
testcase_14 AC 1,121 ms
90,512 KB
testcase_15 AC 126 ms
56,044 KB
testcase_16 AC 125 ms
55,700 KB
testcase_17 AC 127 ms
55,728 KB
testcase_18 AC 125 ms
55,888 KB
testcase_19 AC 126 ms
57,676 KB
testcase_20 AC 124 ms
55,888 KB
testcase_21 AC 125 ms
53,884 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.Collections;
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);

            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);
                }
            }
            weightSum.sort(Collections.reverseOrder());

            out.println(weightSum.get(0));
        }

    }
}

0