結果
| 問題 |
No.561 東京と京都
|
| コンテスト | |
| ユーザー |
lll
|
| 提出日時 | 2017-08-25 23:14:53 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 741 bytes |
| コンパイル時間 | 1,594 ms |
| コンパイル使用メモリ | 166,948 KB |
| 実行使用メモリ | 13,636 KB |
| 最終ジャッジ日時 | 2024-10-15 16:10:29 |
| 合計ジャッジ時間 | 4,916 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 6 WA * 2 TLE * 1 -- * 8 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll N, D;
ll T[101];
ll K[101];
ll ans = 0;
void dfs(ll wage, int type, int i) {
if (i == N) {
ans = max(ans, wage);
return;
}
if (type == 1) {
if (K[i] - T[i] >= D) {
dfs(wage + K[i] - D, type * -1, i + 1);
}
dfs(wage + T[i], type, i + 1);
} else {
if (T[i] - K[i] >= D) {
dfs(wage + T[i] - D, type * -1, i + 1);
}
dfs(wage + K[i], type, i + 1);
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N >> D;
for (ll i = 0; i < N; i++) {
cin >> T[i] >> K[i];
}
dfs(0, 1, 0);
cout << ans << endl;
return 0;
}
lll