#P9871. [NOIP2023] 天天爱打卡

    ID: 11154 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP线段树2023NOIP 提高组O2优化

[NOIP2023] 天天爱打卡

Problem Description

Student T is very enthusiastic about running. To make running more fun, he decides to create an app called Daily Check-in, so that users can check in for running every day.

After finishing development, student T plans to do a trial run, and he asks student Y to help. The trial run lasts for nn days, numbered from 11 to nn.

For student Y, if he chooses to check in for running on some day, his energy value will decrease by dd. Initially, his energy value is 00, and during the trial run his energy value may be negative.

Also, student Y will not check in for running continuously for more than kk days; that is, there cannot exist 1xnk1\le x\le n-k such that he checked in for running from day xx to day x+kx+k.

Student T designed mm challenges in the app. The ii-th challenge (1im1\le i \le m) can be described by three positive integers (xi,yi,vi)(x_i,y_i,v_i), meaning that if on day xix_i the user has already checked in for running continuously for at least yiy_i days (i.e. from day xiyi+1x_i-y_i+1 to day xix_i all days are checked in), then student T will treat the user to a meal, thereby increasing the user’s energy value by viv_i.

Now student Y wants to know: after the nn days of the trial run end, what is the maximum energy value he can reach?

Input Format

This problem’s test points contain multiple groups of testdata.

The first line contains two integers cc and tt, representing the test point ID and the number of testdata groups. For the samples, cc indicates that the sample has the same constraints as test point cc.

Next, for each group of testdata:

  • The first line contains four positive integers n,m,k,dn,m,k,d, representing the number of trial days, the number of challenges, the limit on the maximum consecutive days that student Y can check in for a single running streak, and the energy decrease for each running check-in.
  • The next mm lines each contain three positive integers xi,yi,vix_i,y_i,v_i, describing one challenge.

Output Format

Output one line with one integer, the answer for the corresponding testdata group.

1 1
3 2 2 1
2 2 4
3 2 3

2

Hint

[Sample Explanation #1]

Check in for running on days 1,21,2, do not check in on day 33, and in the end you will obtain an energy value of (1)+(1)+4=2(-1)+(-1)+4=2.

[Sample Explanation #2]

This sample satisfies the constraints of test point 33.

[Sample Explanation #3]

This sample satisfies the constraints of test point 55.

[Sample Explanation #4]

This sample satisfies the constraints of test point 1515.

[Sample Explanation #5]

This sample satisfies the constraints of test point 1717.

[Sample Explanation #6]

This sample satisfies the constraints of test point 1919.

[Constraints]

Let li=xiyi+1l_i=x_i-y_i+1, ri=xir_i=x_i​.

For all testdata, it is guaranteed that 1t101\le t\le 10, 1kn1091\le k\le n\le 10^9, 1m1051\le m\le 10^5, 1lirin1\le l_i\le r_i\le n, 1d,vi1091\le d,v_i\le 10^9.

Test Point ID nn \le mm \le Special Property
1,21, 2 1818 10210 ^ 2 None
3,43, 4 10210 ^ 2
575 \sim 7 10310 ^ 3 10310 ^ 3
8,98, 9 10510 ^ 5
10,1110, 11 10510 ^ 5 10310 ^ 3
121412 \sim 14 10510 ^ 5
15,1615, 16 10910 ^ 9 A
17,1817, 18 B
192119 \sim 21 C
222522 \sim 25 None

Special property A: k102k\le 10^2.

Special property B: 1i<m\forall 1\le i<mri<li+1r_i<l_{i+1}.

Special property C: 1i<jm\forall 1\le i<j\le mli<ljl_i<l_jri<rjr_i<r_j.

Translated by ChatGPT 5