結果
| 問題 |
No.561 東京と京都
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-09-22 09:15:44 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 761 bytes |
| コンパイル時間 | 1,881 ms |
| コンパイル使用メモリ | 158,052 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-08 10:47:32 |
| 合計ジャッジ時間 | 2,399 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 17 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF 1e9
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
using ll = long long;
const ll mod = LLONG_MAX;
//dp[i][j]:=iにいくjは前0次1
int dp[2][2];
int main(){
int n,d;
cin>>n>>d;
rep(i,2)rep(j,2)dp[i][j]=-INF;
dp[0][0]=0;
rep(i,n){
int t,k;
cin>>t>>k;
dp[0][1]=t+max(dp[0][0],dp[1][0]-d);
dp[1][1]=k+max(dp[0][0]-d,dp[1][0]);
dp[0][0]=dp[0][1];
dp[1][0]=dp[1][1];
}
int ans=max(dp[0][0],dp[1][0]);
cout<<ans<<endl;
}