結果

問題 No.561 東京と京都
ユーザー asdf1asdf1
提出日時 2018-03-15 13:34:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 2,456 bytes
コンパイル時間 1,283 ms
コンパイル使用メモリ 145,420 KB
実行使用メモリ 9,816 KB
最終ジャッジ日時 2023-08-22 12:06:42
合計ジャッジ時間 2,511 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,480 KB
testcase_01 AC 3 ms
9,508 KB
testcase_02 AC 3 ms
9,628 KB
testcase_03 AC 3 ms
9,812 KB
testcase_04 AC 3 ms
9,480 KB
testcase_05 AC 3 ms
9,572 KB
testcase_06 AC 3 ms
9,680 KB
testcase_07 AC 3 ms
9,816 KB
testcase_08 AC 3 ms
9,628 KB
testcase_09 AC 3 ms
9,572 KB
testcase_10 AC 3 ms
9,572 KB
testcase_11 AC 3 ms
9,492 KB
testcase_12 AC 3 ms
9,560 KB
testcase_13 AC 3 ms
9,780 KB
testcase_14 AC 3 ms
9,656 KB
testcase_15 AC 3 ms
9,492 KB
testcase_16 AC 3 ms
9,488 KB
testcase_17 AC 3 ms
9,500 KB
testcase_18 AC 3 ms
9,484 KB
testcase_19 AC 3 ms
9,476 KB
testcase_20 AC 3 ms
9,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
#define Size(n) (n).size()

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//long long int kaizyo(long long int hh){
  //  cmp=1;
    //while(hh>1){
      //  cmp=(cmp*hh)%MOD;
        //hh--;
    //}
    //return cmp;
//}
//long long int ruizyo(long long int aa, long long int bb){
  //  if(aa==0){
    //    return 1;
    //}
    //else if(aa%2==0){
      //  long long int tt=ruizyo(aa/2,bb);
        //return (tt*tt)%MOD;
    //}
    //else{
      //  return (ruizyo(aa-1,bb)*bb)%MOD;
    //}
//}フェルマ-のア


//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

//visited=vector<vector<bool>>(10,vector<bool>(10,false));アを全部falseに


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos,dp[2][10000000],t[10000000],k[10000000];
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);

       cin >> n >> d;
       rep(i,n)cin>>t[i]>>k[i];
      //dp[i][j]についてだがiが0ならば東京、1ならば京都で働く様子を示す。j番目まで
       dp[0][0]=t[0];
       dp[1][0]=k[0]-d;
       rrep(i,1,n){
           dp[0][i]=t[i]+max(dp[0][i-1],dp[1][i-1]-d);
           dp[1][i]=k[i]+max(dp[1][i-1],dp[0][i-1]-d);
       }
       Cout(max(dp[0][n-1],dp[1][n-1]));
return 0;
}
0