結果

問題 No.664 超能力者Aと株価予測
ユーザー Grenache
提出日時 2018-03-12 11:49:53
言語 Java
(openjdk 23)
結果
AC  
実行時間 227 ms / 4,000 ms
コード長 1,063 bytes
コンパイル時間 3,766 ms
コンパイル使用メモリ 78,100 KB
実行使用メモリ 41,988 KB
最終ジャッジ日時 2024-11-07 10:07:24
合計ジャッジ時間 7,104 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


public class Main_yukicoder664 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();
		int m = sc.nextInt();
		int k = sc.nextInt();

		int[] a = new int[n + 1];
		for (int i = 0; i <= n; i++) {
			a[i] = sc.nextInt();
		}

		long[] dp = new long[n + 1];
		Arrays.fill(dp, k);
		long max = k;
		for (int l = 0; l < m; l++) {
			for (int i = n; i > 0; i--) {
				for (int j = i - 1; j >= 0; j--) {
					dp[i] = Math.max(dp[i], dp[j] / a[j] * a[i] + dp[j] % a[j]);
					dp[i] = Math.max(dp[i], dp[j]);
				}
			}

			for (int i = 1; i <= n; i++) {
				dp[i] = Math.max(dp[i], dp[i - 1]);
				max = Math.max(max, dp[i]);
			}
		}

		pr.println(max);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0