結果

問題 No.844 split game
ユーザー ttttan2ttttan2
提出日時 2019-06-28 22:34:47
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 1,398 bytes
コンパイル時間 1,420 ms
コンパイル使用メモリ 166,540 KB
実行使用メモリ 8,844 KB
最終ジャッジ日時 2024-07-02 04:57:12
合計ジャッジ時間 4,329 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 56
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,m,a;cin>>n>>m>>a;
    vector<pll> v;
    ll l[m],r[m],p[m];
    rep(i,0,m){
        cin>>l[i]>>r[i]>>p[i];
        v.push_back(make_pair(l[i],i));
    }
    sort(v.begin(),v.end());
    ll dp[n+3][2];
    rep(i,0,n+3){
        rep(j,0,2)dp[i][j]=-inf;
    }
    int now=0;
    dp[0][1]=0;
    rep(i,1,n+1){
        dp[i][0]=max(max(dp[i-1][1],dp[i-1][0]),dp[i][0]);
        while(now<m&&v[now].first==i){
            //cout<<i<<endl;
            ll nr=r[v[now].second],np=p[v[now].second];
            int u;
            if(nr==n)u=0;
            else u=a;
            dp[nr][1]=max(dp[nr][1],dp[i-1][1]+np-u);
            dp[nr][1]=max(dp[nr][1],dp[i-1][0]+np-a-u);
            now++;
        }
    }
    cout<<max((ll)0,max(dp[n][0],dp[n][1]))<<endl;
    
}
0