結果

問題 No.664 超能力者Aと株価予測
ユーザー sekiya9311sekiya9311
提出日時 2018-03-10 00:46:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 238 ms / 4,000 ms
コード長 2,159 bytes
コンパイル時間 2,361 ms
コンパイル使用メモリ 80,824 KB
実行使用メモリ 42,568 KB
最終ジャッジ日時 2024-04-19 07:26:50
合計ジャッジ時間 5,733 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 144 ms
41,632 KB
testcase_01 AC 145 ms
40,604 KB
testcase_02 AC 144 ms
41,828 KB
testcase_03 AC 127 ms
41,292 KB
testcase_04 AC 137 ms
41,656 KB
testcase_05 AC 144 ms
41,772 KB
testcase_06 AC 152 ms
41,680 KB
testcase_07 AC 152 ms
41,484 KB
testcase_08 AC 173 ms
41,676 KB
testcase_09 AC 138 ms
41,524 KB
testcase_10 AC 203 ms
42,424 KB
testcase_11 AC 237 ms
42,284 KB
testcase_12 AC 238 ms
42,336 KB
testcase_13 AC 231 ms
42,568 KB
testcase_14 AC 139 ms
41,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.OptionalLong;
import java.util.Arrays;
import java.util.stream.LongStream;
import java.util.stream.Stream;
import java.util.Scanner;
import java.util.function.Function;

/**
 * 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);
        No664 solver = new No664();
        solver.solve(1, in, out);
        out.close();
    }

    static class No664 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt() + 1;
            int M = in.nextInt();
            long K = in.nextInt();
            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = in.nextInt();
            }
            final long minf = (long) -1e18;
            long[][] dp = new long[N + 1][M + 1];
            for (int i = 0; i < dp.length; i++) {
                Arrays.fill(dp[i], -1);
            }
            dp[0][0] = K;
            for (int i = 0; i < N; i++) {
                for (int j = i + 1; j < N; j++) {
                    for (int k = 0; k < M; k++) {
                        dp[j][k] = Math.max(dp[j][k], dp[i][k]);
                        long foo = dp[i][k];
                        {
                            long bar = foo / A[i];
                            foo -= bar * A[i];
                            foo += bar * A[j];
                        }
                        dp[j][k + 1] = Math.max(dp[j][k + 1], foo);
                    }
                }
            }
            long ans = Arrays.stream(dp).flatMapToLong(new Function<long[], LongStream>() {

                public LongStream apply(long[] longs) {
                    return Arrays.stream(longs);
                }
            }).max().getAsLong();
            out.println(ans);
        }

    }
}

0