Codeforces Round 219 (Div. 1)
C
Watching Fireworks is Fun
Codeforces
2100
原题
← BD →
翻译中…

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.

翻译中…

Input

翻译中…

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*} ≤ 10^{9}; 1 ≤ *t*_{*i*} ≤ 10^{9}$). 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.

翻译中…

Output

翻译中…

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.

翻译中…

样例

Input #1
50 3 1
49 1 1
26 1 4
6 1 10
Output #1
-31
InputCopy OutputCopy
Input #2
10 2 1
1 1000 4
9 1000 4
Output #2
1992
InputCopy OutputCopy
题目信息
题号
372C
时间限制
4 s
内存限制
256 MB
标签
数据结构
动态规划
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。