結果

問題 No.561 東京と京都
ユーザー troro_kelptroro_kelp
提出日時 2018-04-01 23:27:35
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 683 bytes
コンパイル時間 462 ms
コンパイル使用メモリ 68,932 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 12:55:37
合計ジャッジ時間 1,510 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <stack>
using namespace std;
int n, d;
int x, y;
int field[20][20];
int main() {
    cin >> n >> d;
    int dp[101][2]={0};//0が東京,1が京都
    vector<pair<int, int>> fee(101);
    for(int i=0; i<n; ++i){
        int a, b; cin >> a >> b;
        fee[i].first = a; fee[i].second = b;
    }
    dp[1][0] = fee[0].first; dp[1][1] = fee[0].second-d;
    for(int i=1; i<n; ++i){
        dp[i+1][0] = fee[i].first + max(dp[i][0], dp[i][1]-d);
        dp[i+1][1] = fee[i].second + max(dp[i][0]-d, dp[i][1]);
    }
    cout <<max(dp[n][0], dp[n][1]) << endl;
        
    return 0;
}
0