結果
| 問題 |
No.2386 Udon Coupon (Easy)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-07-21 21:43:56 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 884 bytes |
| コンパイル時間 | 4,241 ms |
| コンパイル使用メモリ | 172,800 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-21 23:10:58 |
| 合計ジャッジ時間 | 5,370 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 37 |
ソースコード
import std;
void main () {
int N = readln.chomp.to!int;
int A, B, C; readln.read(A, B, C);
solve(N, A, B, C);
}
void solve (int N, int A, int B, int C) {
// dp[i] := i枚のうどん券で得られる最大割引
int[] dp = new int[](N+1);
// initialize
dp[] = -1;
dp[0] = 0;
auto comsumption = [3, 5, 10];
auto discount = [A, B, C];
foreach (i; 1..N+1) {
foreach (j; 0..cast(int) comsumption.length) {
if (0 <= i-comsumption[j] && dp[ i-comsumption[j] ] != -1) {
dp[i] = max(dp[i], dp[ i-comsumption[j] ] + discount[j]);
}
}
}
long ans = 0;
foreach (price; dp) {
ans = max(ans, price);
}
writeln(ans);
}
void read(T...)(string S, ref T args) {
auto buf = S.split;
foreach (i, ref arg; args) {
arg = buf[i].to!(typeof(arg));
}
}