結果

問題 No.561 東京と京都
ユーザー agisagis
提出日時 2017-08-25 23:12:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 807 bytes
コンパイル時間 1,548 ms
コンパイル使用メモリ 162,984 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-23 16:06:36
合計ジャッジ時間 2,029 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define allsort(v) sort(v.begin(),v.end())
#define allsortg(v)sort(v.begin(),v.end(),greater<int>());
const ll mod = 1e9 + 7;
const int INF = 1e9;

int N, D;
int b[101][2];
ll dp[101][2];
ll DP(int n, int w) {
	if (dp[n][w] != 0)return dp[n][w];
	int x;
	if (w == 0)x = 1;
	else x = 0;
	dp[n][w] = max(DP(n - 1, w) + b[n][w], DP(n - 1, x) - D + b[n][w]);
	return dp[n][w];
}

int main() {
	cin.sync_with_stdio(false);
	cin >> N >> D;
	memset(dp, 0, sizeof(dp));
	rep(i, N) {
		cin >> b[i + 1][0] >> b[i + 1 ][1];
	}
	dp[1][0] = b[1][0]; dp[1][1] = b[1][1] - D;

	cout << max(DP(N,0), DP(N,1)) << endl;

	return 0;
}
0