結果

問題 No.844 split game
ユーザー 0w10w1
提出日時 2020-11-14 19:58:29
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 796 bytes
コンパイル時間 2,111 ms
コンパイル使用メモリ 201,400 KB
最終ジャッジ日時 2025-01-16 00:36:14
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 56
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);

  int N, M, A; {
    cin >> N >> M >> A;
  }

  vector<vector<pair<int, int>>> pr(N + 1); {
    for (int i = 0; i < M; ++i) {
      int L, R, P;
      cin >> L >> R >> P;
      pr[L - 1].emplace_back(P, R);
    }
  }

  const int64_t INF = (int64_t) 1 << 60;
  vector<vector<int64_t>> d(N + 1, vector<int64_t>(2, -INF)); {
    d[0][1] = 0;
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < 2; ++j) {
        d[i + 1][0] = max(d[i + 1][0], d[i][j]);
        d[i + 1][1] = max(d[i + 1][1], d[i][j] - A);
        for (auto [p, r] : pr[i]) {
          if (j) d[r][1] = max(d[r][1], d[i][j] - A + p);
        }
      }
    }
  }

  int64_t res = max(d[N][0], d[N][1] + A);
  cout << res << endl;
}

0