結果

問題 No.844 split game
ユーザー rpy3cpp
提出日時 2019-09-09 11:18:59
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 931 bytes
コンパイル時間 1,715 ms
コンパイル使用メモリ 169,368 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2024-06-28 11:11:44
合計ジャッジ時間 5,464 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 56
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    long long A;
    cin >> N >> M >> A;
    vector<int> Ls(M, 0);
    vector<int> Rs(M, 0);
    vector<long long> Ps(M, 0LL);
    vector<int> idx(N + 1, -1);
    vector<int> next(M, -1);
    for (int i = 0; i < M; ++i) cin >> Ls[i] >> Rs[i] >> Ps[i];
    for (int i = 0; i < M; ++i){
        int r = Rs[i];
        next[i] = idx[r];
        idx[r] = i;
    }
    vector<long long> dp(N + 1, 0);
    long long record = 0;
    for (int i = 1; i <= N; ++i){
        dp[i] = record - A;
        int pos = idx[i];
        while (pos != -1){
            int L = Ls[pos];
            long long score = dp[L - 1] + Ps[pos] - ((i == N) ? 0 : A);
            dp[i] = max(dp[i], score);
            pos = next[pos];
        }
        if (dp[i] > record) record = dp[i];
    }
    cout << record << endl;
    return 0;
}
0