結果
問題 |
No.561 東京と京都
|
ユーザー |
|
提出日時 | 2017-08-25 22:40:55 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 472 bytes |
コンパイル時間 | 1,334 ms |
コンパイル使用メモリ | 159,304 KB |
実行使用メモリ | 13,632 KB |
最終ジャッジ日時 | 2024-10-15 16:03:46 |
合計ジャッジ時間 | 5,018 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 7 TLE * 1 -- * 9 |
ソースコード
#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]; 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; }