結果
| 問題 | No.844 split game | 
| コンテスト | |
| ユーザー |  matsukin11111 | 
| 提出日時 | 2019-06-30 22:41:39 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 171 ms / 2,000 ms | 
| コード長 | 1,791 bytes | 
| コンパイル時間 | 576 ms | 
| コンパイル使用メモリ | 88,912 KB | 
| 実行使用メモリ | 12,428 KB | 
| 最終ジャッジ日時 | 2024-07-07 03:15:37 | 
| 合計ジャッジ時間 | 6,313 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 56 | 
ソースコード
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl;
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
#define INF INT_MAX/2
//segtree
const ll N = 1 << 18;
ll seg[2 * N];
void st(ll p, ll v) {
	p += N - 1;
	seg[p] = v;
	while (p>0) {
		p = (p - 1) / 2;
		seg[p] = max(seg[2 * p + 1], seg[2 * p + 2]);
	}
}
ll query(ll l, ll r, ll a, ll b, ll k) {
	if (r <= a || b <= l)return -inf;
	if (l <= a && b <= r)return seg[k];
	int m = (a + b) / 2;
	return max(query(l, r, a, m, 2 * k + 1), query(l, r, m, b, 2 * k + 2));
}
//[l,r]
ll get(int l, int r) {
	return query(l, r+1, 0, N, 0);
}
ll oneget(int i) {
	return get(i,i);
}
//endsegtree
vector<pair<ll,ll>>R[101010];
int main() {
	ll n, m, a;
	cin >> n >> m >> a;
	
	rep(i, 0, m) {
		ll l, r, p;
		cin >> l >> r >> p;
		R[r].pb({ l,p });
	}
	rep(i,0,n+1)st(i, -inf);
	st(0, 0);
	for (ll r = 1; r <= n; r++) {
		fore(pa, R[r]) {
			ll l = pa.first;
			ll p = pa.second;
			
			ll ma = -inf;
			ll fl = (r == n) ? 0 : a;
			ma = max(ma,oneget(l-1)-fl+p);
			ma = max(ma,get(0,l-2)-a-fl+p);
			st(r,max(oneget(r),ma));
		}
	}
	puts(get(0, n));
	return 0;
}
            
            
            
        