結果

問題 No.844 split game
ユーザー tnakao0123
提出日時 2019-06-29 15:33:16
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 1,427 bytes
コンパイル時間 801 ms
コンパイル使用メモリ 87,968 KB
実行使用メモリ 9,600 KB
最終ジャッジ日時 2024-07-02 05:32:54
合計ジャッジ時間 3,757 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 56
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:51:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   51 |   scanf("%d%d%d", &n, &m, &a);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
main.cpp:55:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   55 |     scanf("%d%d%d", &l, &r, &p);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~

ソースコード

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