結果

問題 No.561 東京と京都
ユーザー darisdaris
提出日時 2022-03-25 14:12:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 2,637 bytes
コンパイル時間 2,870 ms
コンパイル使用メモリ 206,628 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 22:28:25
合計ジャッジ時間 3,653 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#if !__INCLUDE_LEVEL__

#include __FILE__



int main() {
  int n, d;
  input(n, d);
  VVI dp(n + 1, VI(2, 0));
  rep(i, 0, n) {
    int t, k;
    input(t, k);
    if(i == 0) {
      chmax(dp[i + 1][0], dp[i][0] + t);
      chmax(dp[i + 1][1], dp[i][0] + k - d);
    }
    else {
      chmax(dp[i + 1][0], max(dp[i][0] + t, dp[i][1] + t - d));
      chmax(dp[i + 1][1], max(dp[i][0] + k - d, dp[i][1] + k));
      //print(dp[i + 1][0], dp[i + 1][1]);
    }
  }
  print(max(dp[n][0], dp[n][1]));
  return 0;
}
/*

*/

#else
#include <bits/stdc++.h>
using namespace std;

#define _GLIBCXX_DEBUG 
#define rep(i, j, n) for(int i = j; i < n; i++)
#define rrep(i, j, n) for(int i = n - 1; j <= i; i--)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define MOD1 = 998244353;
#define MOD2 = 1000000007;

using LL = long long;
using VI = vector<int>;
using VS = vector<string>;
using VLL = vector<LL>;
using VC = vector<char>;
using VD = vector<double>;
using VB = vector<bool>;
using PII = pair<int, int>;
using PSS = pair<string, string>;
using PIS = pair<int , string>;
using PSI = pair<string, int>;
using PLL = pair<LL, LL>;
using PCC = pair<char, char>;
using VVI = vector<VI>;
using VVS = vector<VS>;
using VVLL = vector<VLL>;
using VVC = vector<VC>;
using VVD = vector<VD>;
using VPII = vector<PII>;
using VPSS = vector<PSS>;
using VPIS = vector<PIS>;
using VPSI = vector<PSI>;
using VPLL = vector<PLL>;

template<typename T> bool chmax(T& a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, const T &b) { if (a > b) { a = b; return true; } return false; }
template<class... T> void input(T&... a) { (cin >> ... >> a); }
template<class T> void print (const T &a) { cout << a << '\n'; }
template<class T, class... Ts> void print(const T& a, const Ts&... b) { cout << a; (cout << ... << (cout << ' ', b)); cout << '\n'; }

LL power(LL n, LL k) { LL res = 1; while(k) if(k & 1) { res *= n; n *= n; k >>= 1; } return res; }
LL power_mod(LL n, LL k, LL mod) { LL res = 1; while(k) { if(k & 1) res = res * n % mod; n = n * n % mod; k >>= 1; } return res; }
bool is_prime(LL n) { if(n == 1) return 0; for(LL i = 2; i * i <= n; i++) if(n % i == 0) return 0; return 1; }
VLL enum_divisors(LL n) { VLL res; for(LL i = 1; i * i <= n; i++)  if(n % i == 0) { res.push_back(i); if(n / i != i) res.push_back(n / i); }  sort(all(res)); return res; }
VPLL prime_factorize(LL n) { VPLL res; for(LL i = 2; i * i <= n; i++) { if(n % i != 0) continue; LL ex = 0; while(n % i == 0) { ex++; n /= i; } res.push_back({i, ex}); } if(n != 1) res.push_back({n, 1}); return res; }

#endif
0