結果

問題 No.561 東京と京都
ユーザー polylogKpolylogK
提出日時 2017-09-08 20:48:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 729 bytes
コンパイル時間 521 ms
コンパイル使用メモリ 61,412 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 20:19:31
合計ジャッジ時間 1,391 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//https://yukicoder.me/problems/no/561
//http://hamayanhamayan.hatenablog.jp/entry/2017/08/26/005044
#include <iostream>
#include <math.h>
#include <cstdio>
#include <algorithm>
#include <string>
#include <string.h>
using namespace std;

const int MAX_N=100;
long long n,d,t,k;
long long dp[MAX_N+1][2]; //dp[day+1][tokyo(0) or kyoto(1)]

int main(){ //dp
	cin >> n >> d;

	memset(dp, -1*(1<<20), sizeof(dp));
	dp[0][0]=0; //in tokyo.
	dp[0][1]=-d; //kyotoに移動すると-dされる.
	
	for(int i=0;i<n;i++){
		cin >> t >> k;
		for(int j=0;j<=1;j++){
			dp[i+1][j] = max(dp[i][j]+(j?k:t), dp[i+1][j]);
			dp[i+1][1-j] = max(dp[i][j]+(1-j?k:t)-d, dp[i+1][1-j]);
		}
	}
	
	cout << max(dp[n][0],dp[n][1]) << endl;
	
	return 0;
}
0