結果
| 問題 |
No.561 東京と京都
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-12-04 03:18:46 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,283 bytes |
| コンパイル時間 | 833 ms |
| コンパイル使用メモリ | 97,284 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-28 15:06:16 |
| 合計ジャッジ時間 | 1,393 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 17 |
ソースコード
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
using namespace std;
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
#define p(p) cout<<(p)<<" ";
#define pb push_back
#define mp make_pair
#define INF 1<<25
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pi;
//int dy[8]={1,1,1,0,0,-1,-1,-1};
//int dx[8]={-1,0,1,-1,1,-1,0,1};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int N,M,l,r,D;
vvi dp,k;
void input(){
cin>>N>>D;
k.resize(N+1,vi(2));
dp.resize(N+1,vi(2,-1));
rep(i,N)cin>>k[i][0]>>k[i][1];
}
int dfs(int day,int p){
if(day>=N)return 0;
if(dp[day][p]!=-1)return dp[day][p];
int ret=dfs(day+1,p)+k[day][p];
ret=max(ret,dfs(day+1,!p)+k[day][!p]-D);
return dp[day][p]=ret;
}
signed main(){
cin.tie(0);
ios::sync_with_stdio(false);
input();
P(dfs(0,0))
return 0;
}