結果
問題 |
No.561 東京と京都
|
ユーザー |
|
提出日時 | 2025-04-18 23:28:37 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 878 bytes |
コンパイル時間 | 2,150 ms |
コンパイル使用メモリ | 196,328 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-04-18 23:28:40 |
合計ジャッジ時間 | 3,271 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 17 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,j,n) for(ll i=j; n>i; ++i) const ll inf = -1e12; int main(){ ll n,d; cin >> n >> d; vector<ll> t(n),k(n); rep(i,0,n) cin >> t[i] >> k[i]; //dp[n][city] := n日目にcityにいるときの最大値 //0 -> tokyo, 1-> kyoto; ll dp[n+1][2]; for(ll i=0; n>=i; ++i){ for(ll j=0; 2>j; ++j){ dp[i][j] = inf; } } dp[0][0] = 0; for(ll i=1; n>=i; ++i){ for(ll j=0; 2>j; ++j){ dp[i][j] = max(dp[i-1][j],dp[i-1][1-j]-d); if(j == 0) dp[i][j] += t[i-1]; else dp[i][j] += k[i-1]; } } cout << max(dp[n][0],dp[n][1]) << endl; /*for(int i=0; 2>i; ++i){ for(int j=0; n>=j; ++j){ cout << dp[j][i] << " "; } cout << endl; } cout << endl;*/ }