結果
| 問題 | No.844 split game | 
| コンテスト | |
| ユーザー |  totori_nyaa | 
| 提出日時 | 2019-08-06 16:39:23 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 48 ms / 2,000 ms | 
| コード長 | 700 bytes | 
| コンパイル時間 | 1,613 ms | 
| コンパイル使用メモリ | 172,876 KB | 
| 実行使用メモリ | 9,216 KB | 
| 最終ジャッジ日時 | 2024-07-18 14:05:59 | 
| 合計ジャッジ時間 | 4,506 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 56 | 
ソースコード
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
signed main(){
    //cout << setprecision(12) ;
    ios::sync_with_stdio(false);
	cin.tie(0);
    ll n,m,a;
    cin>>n>>m>>a;
    vector<vector<pair<ll,ll>>> v(111111);
    for(ll i=0;i<m;i++){
        ll l,r,c;
        cin>>l>>r>>c;
        l--;
        v[r].push_back(make_pair(l,c));
    }
    vector<ll> dp(n+1,-a);
    dp[0]=0,dp[n]=0;
    ll ans=-1e18;
    
    for(ll i=1;i<=n;i++){
        ll ret=0;
        for(auto j:v[i]){
            ret = max(ret,dp[j.first]+j.second);
        }
        dp[i] = max(dp[i]+ret,ans-a);
        ans = max(ans,dp[i]);
        
    }
    ans = max(ans,0LL);
    cout<<ans<<endl;
    
}
            
            
            
        