結果
| 問題 | No.844 split game | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2019-06-28 23:12:37 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 108 ms / 2,000 ms | 
| コード長 | 1,342 bytes | 
| コンパイル時間 | 1,230 ms | 
| コンパイル使用メモリ | 121,972 KB | 
| 実行使用メモリ | 5,504 KB | 
| 最終ジャッジ日時 | 2024-07-02 05:09:20 | 
| 合計ジャッジ時間 | 5,078 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 56 | 
ソースコード
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;
class Data
{
public:
    int l, r;
    long long p;
    bool operator<(const Data& other) const{
        return l < other.l;
    }
};
const long long INF = LLONG_MAX / 2;
int main()
{
    int n, m;
    long long a;
    cin >> n >> m >> a;
    vector<Data> v(m);
    for(int i=0; i<m; ++i){
        cin >> v[i].l >> v[i].r >> v[i].p;
        -- v[i].l;
    }
    sort(v.begin(), v.end());
    vector<long long> dp(n+1, -INF);
    dp[0] = 0;
    int k = 0;
    long long tmp = 0;
    for(int i=0; i<m; ++i){
        while(k <= v[i].l){
            dp[k] = max(dp[k], tmp - a);
            tmp = max(tmp, dp[k]);
            ++ k;
        }
        dp[v[i].r] = max(dp[v[i].r], dp[v[i].l] + v[i].p - a);
    }
    long long ans = *max_element(dp.begin(), dp.end());
    ans = max(ans, dp[n] + a);
    cout << ans << endl;
    return 0;
}
            
            
            
        