結果
| 問題 | No.561 東京と京都 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-01-23 01:19:55 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 611 bytes |
| 記録 | |
| コンパイル時間 | 547 ms |
| コンパイル使用メモリ | 81,676 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2026-01-23 01:19:57 |
| 合計ジャッジ時間 | 1,474 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 17 |
ソースコード
#include <iostream>
#include <cstring>
using namespace std;
typedef long long LL;
const int N = 110;
int n, d, a[N][2];
LL f[N][2];
int main() {
// freopen("work.in", "r", stdin);
// freopen("work.out", "w", stdout);
scanf("%d%d", &n, &d);
for (int i = 1; i <= n; ++i) scanf("%d%d", &a[i][0], &a[i][1]);
memset(f, 0xcf, sizeof(f));
f[0][0] = 0LL;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < 2; ++j) {
f[i][j] = max(f[i - 1][j] + a[i][j], f[i - 1][1 - j] + a[i][j] - d);
}
}
printf("%lld\n", max(f[n][0], f[n][1]));
return 0;
}