結果

問題 No.844 split game
ユーザー akakimidoriakakimidori
提出日時 2019-07-06 09:46:35
言語 C
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,161 bytes
コンパイル時間 478 ms
コンパイル使用メモリ 30,976 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-24 13:12:30
合計ジャッジ時間 4,324 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33 WA * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))
#define SORT(a,num,cmp) qsort((a),(num),sizeof(*(a)),cmp)

typedef struct range {
  i32 l, r, p;
} range;

int cmp_range (const void *a, const void *b) {
  i32 d = ((range *)a)->r - ((range *)b)->r;
  return d == 0 ? 0 : d < 0 ? -1 : 1;
}

void run (void) {
  i32 n, m, a;
  scanf ("%" SCNi32 "%" SCNi32 "%" SCNi32, &n, &m, &a);
  range *q = ALLOC (m, range);
  for (i32 i = 0; i < m; ++i) {
    i32 l, r, p;
    scanf ("%" SCNi32 "%" SCNi32 "%" SCNi32, &l, &r, &p);
    l--;
    q[i] = (range) {l, r, p};
  }
  SORT (q, m, cmp_range);
  i64 *dp = ALLOC (n + 1, i64);
  for (i32 i = 0, j = 0; i <= n; ++i) {
    i64 cost = 0 < i && i < n ? -a : 0;
    i64 max = cost;
    for (; j < m && q[j].r == i; ++j) {
      max = MAX (max, cost + q[j].p + dp[q[j].l]);
    }
    dp[i] = max;
  }
  i64 ans = 0;
  for (i32 i = 0; i <= n; ++i) {
    ans = MAX (ans, dp[i]);
  }
  printf ("%" PRIi64 "\n", ans);
}

int main (void) {
  run();
  return 0;
}
0