結果

問題 No.844 split game
ユーザー risujiroh
提出日時 2019-06-28 22:43:18
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 676 bytes
コンパイル時間 1,708 ms
コンパイル使用メモリ 173,568 KB
実行使用メモリ 8,320 KB
最終ジャッジ日時 2024-07-02 05:01:15
合計ジャッジ時間 4,559 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 56
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, m, a; cin >> n >> m >> a;
  struct S { int l, p; };
  VV<S> d(n + 1);
  while (m--) {
    int l, r, p; cin >> l >> r >> p, --l;
    d[r].emplace_back(S{l, p});
  }
  V<lint> dp(n + 1, -1e18);
  dp[0] = 0;
  lint mx = 0;
  for (int i = 1; i <= n; ++i) {
    dp[i] = mx - a;
    for (S e : d[i]) {
      dp[i] = max(dp[i], dp[e.l] + e.p - a);
    }
    mx = max(mx, dp[i]);
  }
  dp[n] += a;
  cout << *max_element(begin(dp), end(dp)) << '\n';
}
0