結果
| 問題 |
No.844 split game
|
| コンテスト | |
| ユーザー |
Yang33
|
| 提出日時 | 2019-07-05 14:41:17 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 130 ms / 2,000 ms |
| コード長 | 930 bytes |
| コンパイル時間 | 1,811 ms |
| コンパイル使用メモリ | 177,772 KB |
| 実行使用メモリ | 13,184 KB |
| 最終ジャッジ日時 | 2024-09-21 18:19:41 |
| 合計ジャッジ時間 | 7,322 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 56 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,t) for(int i = s; i < t; i++)
using LL = long long;
using VL = vector<LL>;
int main() {
int N, M, A; cin >> N >> M >> A;
using PII = pair<int, int>;
vector<vector<PII>>seg(N + 1);
FOR(i, 0, M) {
int L, R, V; cin >> L >> R >> V;
seg[R].emplace_back(L, V);
}
const int USED = 1;
const int SETED = 0;
const LL LINF = 1e18;
vector<VL> dp(N + 1, VL(2, -LINF));
auto setmax = [](LL &a, LL b) {a = max(a, b); };
dp[0][SETED] = 0;
LL allmax = 0;
FOR(R, 1, N + 1) {
for (auto it : seg[R]) {
int L = it.first; LL v = it.second + (R == N ? 0 : -A);
setmax(dp[R][USED], dp[L - 1][SETED] + v);
}
setmax(dp[R][SETED], allmax - A);
setmax(dp[R][SETED], dp[R][USED]);
setmax(allmax, dp[R][SETED]);
setmax(allmax, dp[R][USED]);
}
LL ans = 0;
FOR(i, 0, N + 1) {
setmax(ans, dp[i][USED]);
setmax(ans, dp[i][SETED]);
}
cout << ans << endl;
}
Yang33