結果

問題 No.844 split game
ユーザー seriru13
提出日時 2019-09-07 11:22:50
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,590 bytes
コンパイル時間 1,438 ms
コンパイル使用メモリ 112,976 KB
最終ジャッジ日時 2025-01-07 17:08:54
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 56
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

// 長さNの線があって、そのうちいくつかの区間に制約があるという状況で何かを最適化する、
// という問題ではDPが有効な場合がある。

using P = pair<ll,ll>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n, m, a;
    cin >> n >> m >> a;

    vector<vector<P>> v(n+1);
    ll p;
    rep(i, m) {
        int l,r;
        cin >> l >> r >> p;
        v[r].push_back(P(l, p));
    }

    ll ma = 0;
    vector<ll> dp(n+100);
    for (int i = 1; i <= n; ++i) {
        dp[i] = ma - a;
        for (auto x : v[i]) {
            dp[i] = max(dp[i], dp[x.first - 1] + x.second - (i == n ? 0 : a));
        }
        ma = max(ma, dp[i]);
    }

    cout << ma << endl;
}
0