CF372C.Watching Fireworks is Fun

提高+/省选-

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A festival will be held in a town's main street. There are n sections in the main street. The sections are numbered 1 through n from left to right. The distance between each adjacent sections is 1.

In the festival m fireworks will be launched. The i-th (1 ≤ i ≤ m) launching is on time t__i at section a__i. If you are at section x (1 ≤ x ≤ n) at the time of i-th launching, you'll gain happiness value b__i - |a__i - x| (note that the happiness value might be a negative value).

You can move up to d length units in a unit time interval, but it's prohibited to go out of the main street. Also you can be in an arbitrary section at initial time moment (time equals to 1), and want to maximize the sum of happiness that can be gained from watching fireworks. Find the maximum total happiness.

Note that two or more fireworks can be launched at the same time.

一场节日庆典将在小镇的主街上举行。主街分为 nn 个区段,从左到右依次编号为 11 到 nn,相邻区段之间的距离为 11。

庆典期间将燃放 mm 次烟花。第 ii 次(1≤i≤m1 \leq i \leq m)烟花在时刻 tit_i 于区段 aia_i 处燃放。若你在第 ii 次烟花燃放的时刻恰好位于区段 xx(1≤x≤n1 \leq x \leq n),则你获得的快乐值为 bi−∣ai−x∣b_i - |a_i - x|(注意:该快乐值可能为负数)。

你每单位时间最多可移动 dd 个长度单位,但禁止离开主街(即位置必须始终满足 1≤x≤n1 \leq x \leq n)。初始时刻(时间为 11)你可以位于任意区段,并希望最大化观看所有烟花所获得的总快乐值。请计算所能获得的最大总快乐值。

注意:可能有两次或更多次烟花在同一时刻燃放。

输入格式

The first line contains three integers n, m, d (1 ≤ n ≤ 150000; 1 ≤ m ≤ 300; 1 ≤ d ≤ n).

Each of the next m lines contains integers a__i, b__i, t__i (1 ≤ a__i ≤ n; 1 ≤ b__i ≤ 109; 1 ≤ t__i ≤ 109). The i-th line contains description of the i-th launching.

It is guaranteed that the condition t__i ≤ t__i + 1 (1 ≤ i < m) will be satisfied.

第一行包含三个整数 nn、mm、dd(1 ≤ n ≤ 1500001 \le n \le 150000;1 ≤ m ≤ 3001 \le m \le 300;1 ≤ d ≤ n1 \le d \le n)。

接下来的 mm 行,每行包含三个整数 aia_i、bib_i、tit_i(1 ≤ ai ≤ n1 \le a_i \le n;1 ≤ bi ≤ 1091 \le b_i \le 10^9;1 ≤ ti ≤ 1091 \le t_i \le 10^9)。第 ii 行描述第 ii 次发射。

保证满足条件 ti ≤ ti+1t_i \le t_{i+1}(1 ≤ i < m1 \le i < m)。

输出格式

Print a single integer — the maximum sum of happiness that you can gain from watching all the fireworks.

Please, do not write the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.

输出一个整数——观看所有烟花所能获得的最大幸福总和。

请注意,在 C++ 中不要使用 %lld 说明符来读取或写入 64 位整数。推荐使用 cin、cout 流,或 %I64d 说明符。

输入输出样例

  • 输入#1

    50 3 1
    49 1 1
    26 1 4
    6 1 10

    输出#1

    -31
  • 输入#2

    10 2 1
    1 1000 4
    9 1000 4

    输出#2

    1992

输入解题思路,AI测评打分。不知道怎么写?

首页