結果
問題 | No.844 split game |
ユーザー |
|
提出日時 | 2019-06-28 21:39:05 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 126 ms / 2,000 ms |
コード長 | 781 bytes |
コンパイル時間 | 1,656 ms |
コンパイル使用メモリ | 172,108 KB |
実行使用メモリ | 8,320 KB |
最終ジャッジ日時 | 2024-07-02 04:30:12 |
合計ジャッジ時間 | 5,797 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 56 |
ソースコード
#include <bits/stdc++.h> using namespace std; void chmax(int64_t& a, int64_t b){ a = max(a, b); } int main(){ int N, M, A; cin >> N >> M >> A; vector<pair<int, int>> R2LP[100001]; for(int i=0; i<M; i++){ int l, r, p; cin >> l >> r >> p; R2LP[r].push_back({l, p}); } const int64_t INF = 1e18; vector<int64_t> dp(N+1, -INF); dp[0] = 0; int64_t mx = 0; for(int i=1; i<=N; i++){ for(auto& p : R2LP[i]){ int l = p.first, pt = p.second; int64_t cost = (i == N ? 0 : A); chmax(dp[i], dp[l-1] - cost + pt); } chmax(dp[i], mx - A); chmax(mx, dp[i]); } int64_t ans = *max_element(dp.begin(), dp.end()); cout << ans << endl; return 0; }