結果

問題 No.844 split game
ユーザー tnakao0123tnakao0123
提出日時 2019-06-29 15:33:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 1,427 bytes
コンパイル時間 665 ms
コンパイル使用メモリ 87,096 KB
実行使用メモリ 9,492 KB
最終ジャッジ日時 2023-09-14 23:13:52
合計ジャッジ時間 4,173 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
7,140 KB
testcase_01 AC 17 ms
8,172 KB
testcase_02 AC 38 ms
8,128 KB
testcase_03 AC 30 ms
8,416 KB
testcase_04 AC 16 ms
7,152 KB
testcase_05 AC 41 ms
8,732 KB
testcase_06 AC 15 ms
7,020 KB
testcase_07 AC 12 ms
7,636 KB
testcase_08 AC 9 ms
6,520 KB
testcase_09 AC 30 ms
7,156 KB
testcase_10 AC 44 ms
8,524 KB
testcase_11 AC 44 ms
9,120 KB
testcase_12 AC 29 ms
7,080 KB
testcase_13 AC 20 ms
6,676 KB
testcase_14 AC 20 ms
7,676 KB
testcase_15 AC 48 ms
9,344 KB
testcase_16 AC 48 ms
9,380 KB
testcase_17 AC 48 ms
9,356 KB
testcase_18 AC 49 ms
9,492 KB
testcase_19 AC 49 ms
9,348 KB
testcase_20 AC 48 ms
9,428 KB
testcase_21 AC 47 ms
9,424 KB
testcase_22 AC 48 ms
9,428 KB
testcase_23 AC 5 ms
6,016 KB
testcase_24 AC 6 ms
6,128 KB
testcase_25 AC 5 ms
6,040 KB
testcase_26 AC 4 ms
6,056 KB
testcase_27 AC 6 ms
6,120 KB
testcase_28 AC 4 ms
5,960 KB
testcase_29 AC 6 ms
6,116 KB
testcase_30 AC 6 ms
6,244 KB
testcase_31 AC 6 ms
6,068 KB
testcase_32 AC 4 ms
6,016 KB
testcase_33 AC 7 ms
6,000 KB
testcase_34 AC 5 ms
6,020 KB
testcase_35 AC 7 ms
6,020 KB
testcase_36 AC 5 ms
5,932 KB
testcase_37 AC 9 ms
6,136 KB
testcase_38 AC 15 ms
6,464 KB
testcase_39 AC 27 ms
7,176 KB
testcase_40 AC 11 ms
7,172 KB
testcase_41 AC 3 ms
6,132 KB
testcase_42 AC 3 ms
5,936 KB
testcase_43 AC 3 ms
5,956 KB
testcase_44 AC 4 ms
6,096 KB
testcase_45 AC 3 ms
5,884 KB
testcase_46 AC 3 ms
5,872 KB
testcase_47 AC 3 ms
5,952 KB
testcase_48 AC 3 ms
5,916 KB
testcase_49 AC 4 ms
5,888 KB
testcase_50 AC 3 ms
5,844 KB
testcase_51 AC 3 ms
5,808 KB
testcase_52 AC 3 ms
5,808 KB
testcase_53 AC 4 ms
5,944 KB
testcase_54 AC 3 ms
5,980 KB
testcase_55 AC 3 ms
5,816 KB
testcase_56 AC 3 ms
5,812 KB
testcase_57 AC 3 ms
5,844 KB
testcase_58 AC 3 ms
5,828 KB
testcase_59 AC 3 ms
6,100 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 844.cc:  No.844 split game - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const long long LINF = 1LL << 62;

/* typedef */

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

/* global variables */

vpii nbrs[MAX_N + 1];
ll dp[MAX_N + 1][2];

/* subroutines */

inline void setmax(ll &a, ll b) { if (a < b) a = b; }

/* main */

int main() {
  int n, m, a;
  scanf("%d%d%d", &n, &m, &a);

  for (int i = 0; i < m; i++) {
    int l, r, p;
    scanf("%d%d%d", &l, &r, &p);
    l--;
    nbrs[l].push_back(pii(r, p));
  }

  for (int i = 0; i <= n; i++) dp[i][0] = dp[i][1] = -LINF;
  dp[0][1] = 0;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 2; j++)
      if (dp[i][j] > -LINF) {
	setmax(dp[i + 1][0], dp[i][j]);
	setmax(dp[i + 1][1], dp[i][j] - a);
      }

    if (dp[i][1] > -LINF) {
      vpii &nbri = nbrs[i];
      for (vpii::iterator vit = nbri.begin(); vit != nbri.end(); vit++)
	setmax(dp[vit->first][1], dp[i][1] + vit->second - a);
    }
  }

  printf("%lld\n", max(dp[n][0], dp[n][1] + a));
  return 0;
}
0