結果
問題 | No.561 東京と京都 |
ユーザー |
|
提出日時 | 2017-08-25 23:00:29 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 624 bytes |
コンパイル時間 | 575 ms |
コンパイル使用メモリ | 70,916 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-15 16:33:22 |
合計ジャッジ時間 | 1,216 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 17 |
ソースコード
#include <iostream>#include <stdio.h>#include <string>#include <vector>#include <set>#include <cmath>#include <algorithm>#define MP make_pairusing ll = long long;using namespace std;int main(){ll N, D;cin >> N >> D;vector<ll>T(N);vector<ll>K(N);for(int i=0; i < N; i++){cin >> T[i];cin >> K[i];}vector<vector<ll> >dp(N, vector<ll>(2));dp[0][0] = T[0];dp[0][1] = K[0]-D;for(int i=1; i < N; i++){dp[i][0] = max(dp[i-1][0]+T[i], dp[i-1][1]-D+T[i]);dp[i][1] = max(dp[i-1][0]-D+K[i], dp[i-1][1]+K[i]);}cout << max(dp[N-1][0], dp[N-1][1]) << endl;return 0;}