結果
| 問題 |
No.664 超能力者Aと株価予測
|
| コンテスト | |
| ユーザー |
htensai
|
| 提出日時 | 2020-02-06 17:18:15 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,822 bytes |
| コンパイル時間 | 2,229 ms |
| コンパイル使用メモリ | 77,512 KB |
| 実行使用メモリ | 50,416 KB |
| 最終ジャッジ日時 | 2024-09-25 06:51:02 |
| 合計ジャッジ時間 | 3,918 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 WA * 1 |
ソースコード
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());
}
int[][] buyDp = new int[m + 1][n + 2];
int[][] sellDp = new int[m + 1][n + 2];
int[][] restDp = new int[m + 1][n + 2];
Arrays.fill(sellDp[0], k);
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n + 1; j++) {
int buy = sellDp[i - 1][j - 1] / prices[j];
int 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]);
}
}
htensai