結果
| 問題 |
No.561 東京と京都
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-03-25 14:12:40 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 2,637 bytes |
| コンパイル時間 | 2,088 ms |
| コンパイル使用メモリ | 206,596 KB |
| 最終ジャッジ日時 | 2025-01-28 11:20:07 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 17 |
ソースコード
#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