結果
問題 | No.561 東京と京都 |
ユーザー |
|
提出日時 | 2017-08-25 23:00:36 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 1,336 bytes |
コンパイル時間 | 630 ms |
コンパイル使用メモリ | 104,748 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-12 21:44:51 |
合計ジャッジ時間 | 1,322 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 17 |
ソースコード
// tested by Hightail - https://github.com/dj3500/hightailimport std.stdio, std.string, std.conv, std.algorithm;import std.range, std.array, std.math, std.typecons, std.container, core.bitop;immutable inf = 10^^9 + 7;void main() {int n, d;long[] t, k;scan(n, d);t = new long[](n);k = new long[](n);foreach (i ; 0 .. n) {scan(t[i], k[i]);}auto dp = new long[][](n + 1, 2);dp[0][1] = -inf;foreach (i ; 0 .. n) {foreach (j ; 0 .. 2) {if (j == 0) {dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + t[i]);dp[i + 1][j ^ 1] = max(dp[i + 1][j ^ 1], dp[i][j] - d + k[i]);}else {dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + k[i]);dp[i + 1][j ^ 1] = max(dp[i + 1][j ^ 1], dp[i][j] - d + t[i]);}}}writeln(max(dp[n][0], dp[n][1]));}void scan(T...)(ref T args) {string[] line = readln.split;foreach (ref arg; args) {arg = line.front.to!(typeof(arg));line.popFront();}assert(line.empty);}void fillAll(R, T)(ref R arr, T value) {static if (is(typeof(arr[] = value))) {arr[] = value;}else {foreach (ref e; arr) {fillAll(e, value);}}}