結果

問題 No.561 東京と京都
ユーザー seriru13
提出日時 2019-04-30 18:31:44
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,347 bytes
コンパイル時間 1,139 ms
コンパイル使用メモリ 104,736 KB
最終ジャッジ日時 2025-01-07 03:17:12
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, d;
  cin >> n >> d;
  vector<ll> t(n), k(n);
  rep(i, n) cin >> t[i] >> k[i];

  ll dp[n + 2][2];
  memset(dp, 0, sizeof(dp));

  dp[0][0] = 0;
  dp[0][1] = -d;

  for (int i = 0; i < n; ++i) {
    // area: 0(東京), 1(京都)
    dp[i+1][0] += max(dp[i][0] + t[i], dp[i][1] - d + t[i]);
    dp[i+1][1] += max(dp[i][0] - d + k[i], dp[i][1] + k[i]);
  }
/*
  debug(dp[n][0]);
  debug(dp[n][1]);*/
  cout << max(dp[n][0], dp[n][1]) << endl;
}
0