結果
| 問題 |
No.844 split game
|
| コンテスト | |
| ユーザー |
tottoripaper
|
| 提出日時 | 2019-07-03 23:21:15 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 64 ms / 2,000 ms |
| コード長 | 993 bytes |
| コンパイル時間 | 1,837 ms |
| コンパイル使用メモリ | 172,364 KB |
| 実行使用メモリ | 17,152 KB |
| 最終ジャッジ日時 | 2024-09-17 06:19:37 |
| 合計ジャッジ時間 | 5,984 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 56 |
ソースコード
#include <bits/stdc++.h>
#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))
using ll = std::int64_t;
using P = std::tuple<int,int>;
int N, M, A;
std::vector<P> v[100100];
ll dp[100100][2];
ll rec(int x, bool has){
if(x == 0){
return 0;
}
if(dp[x][has] != -1){
return dp[x][has];
}
ll mx = rec(x - 1, 0);
for(auto &pa : v[x]){
int l, p;
std::tie(l, p) = pa;
mx = std::max(mx, rec(l, 1) + (has ? 0 : -A) + (l == 0 ? 0 : -A) + p);
}
return dp[x][has] = mx;
}
int main(){
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
std::cin >> N >> M >> A;
for(int i=0;i<M;++i){
int l, r, p;
std::cin >> l >> r >> p;
l -= 1;
r -= 1;
v[r+1].emplace_back(l, p);
}
memset(dp, -1, sizeof(dp));
ll mx = rec(N, 1);
std::cout << mx << std::endl;
}
tottoripaper