CF372C.Watching Fireworks is Fun

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

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

In the festival mm fireworks will be launched. The ii -th ( 1<=i<=m1<=i<=m ) launching is on time tit_{i} at section aia_{i} . If you are at section xx ( 1<=x<=n1<=x<=n ) at the time of ii -th launching, you'll gain happiness value biaixb_{i}-|a_{i}-x| (note that the happiness value might be a negative value).

You can move up to dd 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 11 ), 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.

输入格式

The first line contains three integers nn , mm , dd ( 1<=n<=150000; 1<=m<=300; 1<=d<=n1<=n<=150000; 1<=m<=300; 1<=d<=n ).

Each of the next mm lines contains integers aia_{i} , bib_{i} , tit_{i} ( 1<=ai<=n; 1<=bi<=109; 1<=ti<=1091<=a_{i}<=n; 1<=b_{i}<=10^{9}; 1<=t_{i}<=10^{9} ). The ii -th line contains description of the ii -th launching.

It is guaranteed that the condition ti<=ti+1t_{i}<=t_{i+1} ( 1<=i<m ) will be satisfied.

输出格式

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.

输入输出样例

  • 输入#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
    
首页