結果

問題 No.561 東京と京都
ユーザー albicillaalbicilla
提出日時 2017-09-22 09:15:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 761 bytes
コンパイル時間 1,300 ms
コンパイル使用メモリ 159,484 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-25 22:40:45
合計ジャッジ時間 2,088 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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;
}
0