結果
問題 | No.561 東京と京都 |
ユーザー |
|
提出日時 | 2017-08-25 23:03:36 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 923 bytes |
コンパイル時間 | 721 ms |
コンパイル使用メモリ | 120,708 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-12 21:44:56 |
合計ジャッジ時間 | 1,355 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 17 |
ソースコード
import std.algorithm, std.conv, std.range, std.stdio, std.string; import std.container; // SList, DList, BinaryHeap import std.typecons; // Tuple, Nullable, BigFlags import std.math; // math functions import std.numeric; // gcd, fft import std.bigint; // BigInt import std.random; // random import std.bitmanip; // BitArray import core.bitop; // bit operation import std.regex; // RegEx import std.uni; // unicode void main() { auto rd = readln.split, n = rd[0].to!size_t, d = rd[1].to!int; auto t = new int[](n), k = new int[](n); foreach (i; 0..n) { auto rd2 = readln.split.to!(int[]); t[i] = rd2[0]; k[i] = rd2[1]; } auto dp1 = new int[](n), dp2 = new int[](n); dp1[0] = t[0]; dp2[0] = k[0] - d; foreach (i; 1..n) { dp1[i] = max(dp1[i-1]+t[i], dp2[i-1]+t[i]-d); dp2[i] = max(dp1[i-1]+k[i]-d, dp2[i-1]+k[i]); } writeln(max(dp1[$-1], dp2[$-1])); }