結果
問題 | No.561 東京と京都 |
ユーザー |
|
提出日時 | 2017-08-25 22:42:03 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 507 bytes |
コンパイル時間 | 1,338 ms |
コンパイル使用メモリ | 158,320 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-15 16:31:08 |
合計ジャッジ時間 | 1,973 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 17 |
ソースコード
#include <bits/stdc++.h>using namespace std;int n, d;int a[101], b[101];int dp[101][2];int solver(int v = -1, bool f = false) {if (v == n) return 0;int &res = dp[v][f];if (v != -1 && ~res) return res;res = max(solver(v + 1, false) + a[v + 1] - (f ? d : 0),solver(v + 1, true) + b[v + 1] - (f ? 0 : d));return res;}int main() {cin >> n >> d;for (int i = 0; i < n; ++i) {cin >> a[i] >> b[i];}memset(dp, -1, sizeof(dp));cout << solver() << endl;}