結果
問題 |
No.664 超能力者Aと株価予測
|
ユーザー |
![]() |
提出日時 | 2020-02-06 17:19:58 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 58 ms / 4,000 ms |
コード長 | 1,830 bytes |
コンパイル時間 | 2,218 ms |
コンパイル使用メモリ | 77,492 KB |
実行使用メモリ | 50,316 KB |
最終ジャッジ日時 | 2024-09-25 06:51:06 |
合計ジャッジ時間 | 3,699 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 |
ソースコード
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] first = br.readLine().split(" ", 3); int n = Integer.parseInt(first[0]); int m = Integer.parseInt(first[1]); int k = Integer.parseInt(first[2]); int[] prices = new int[n + 2]; for (int i = 1; i <= n + 1; i++) { prices[i] = Integer.parseInt(br.readLine()); } long[][] buyDp = new long[m + 1][n + 2]; long[][] sellDp = new long[m + 1][n + 2]; long[][] restDp = new long[m + 1][n + 2]; Arrays.fill(sellDp[0], k); for (int i = 1; i <= m; i++) { for (int j = 1; j <= n + 1; j++) { long buy = sellDp[i - 1][j - 1] / prices[j]; long rest = sellDp[i - 1][j - 1] % prices[j]; if (buy == buyDp[i - 1][j]) { rest = Math.max(rest, restDp[i - 1][j]); } else if (buy < buyDp[i - 1][j]) { buy = buyDp[i - 1][j]; rest = restDp[i - 1][j]; } if (buy == buyDp[i][j - 1]) { rest = Math.max(rest, restDp[i][j - 1]); } else if (buy < buyDp[i][j - 1]) { buy = buyDp[i][j - 1]; rest = restDp[i][j - 1]; } buyDp[i][j] = buy; restDp[i][j] = rest; } for (int j = 1; j <= n + 1; j++) { sellDp[i][j] = Math.max(Math.max(sellDp[i - 1][j], sellDp[i][j - 1]), Math.max(sellDp[i][j], buyDp[i][j - 1] * prices[j] + restDp[i][j - 1])); } } System.out.println(sellDp[m][n + 1]); } }