#P12247. 跳舞机

    ID: 11728 远端评测题 1500ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划 DP线段树洛谷原创O2优化扫描线洛谷月赛

跳舞机

Description

Little O wants to operate an arcade, where the dance machine's operation is crucial.

There is one dance machine in Little O's arcade that can accommodate at most one player at any given time. Each game session requires a complete and continuous playtime of exactly kk minutes.

The venue will be open for mm minutes. During this period, nn players want to use the dance machine, numbered from 11 to nn. Player ii will be present from minute lil_i to minute rir_i (inclusive) and can play any number of complete game sessions during their stay. Each completed session generates wiw_i excitement points. Note that for player ii to play a session, the entire kk-minute duration must be fully contained within their stay interval [li,ri][l_i, r_i].

Little O wants to maximize the total excitement points from all players. Your task is to determine the maximum possible total excitement.

Input Format

The input consists of n+1n+1 lines:

  • Line 11: Three integers nn, mm, kk - number of players, operating duration, and session length.
  • Lines 22 to n+1n+1: Each line contains three integers lil_i, rir_i, wiw_i - the stay interval and excitement per session for player ii.

Output Format

Output a single integer - the maximum total excitement possible.

3 6 2
1 5 1
5 6 2
5 6 3

5
4 7 3
1 7 1
2 5 4
4 7 5
1 2 10
9

Hint

Sample #1 Explanation

Optimal schedule:

  • Player 11 plays at [1,2][1,2] and [3,4][3,4]
  • Player 33 plays at [5,6][5,6]

Total: 1×2+3×1=51\times 2 + 3\times 1 = 5 points (maximum possible)

Sample #2 Explanation

Optimal schedule:

  • Player 22 plays at [2,4][2,4]
  • Player 33 plays at [5,7][5,7]

Total: 4+5=94 + 5 = 9 points (maximum possible)

Constraints

  • 1n,m,k5×1051\le n,m,k\le 5\times 10^5
  • kmk\le m
  • 1lirim1\le l_i\le r_i\le m
  • 1wi1091\le w_i\le 10^9

Let Li=rili+1L_i = r_i - l_i + 1. Subtask constraints:

Test Case nn Range mm Range Special Properties
131\sim 3 n5n\le 5 m10m\le 10 wi20w_i\le 20
464\sim 6 n105n\le 10^5 m105m\le 10^5 Li=k=1L_i=k=1
7107\sim10 n1000n\le 1000 m1000m\le 1000 None
111311\sim 13 n105n\le 10^5 m105m\le 10^5 Li=kL_i=k
141614\sim 16 n100n\le 100 None
172017\sim 20 n105n\le 10^5 wi=1w_i=1
21,2221,22 None
232523\sim 25 n5×105n\le 5\times 10^5 m5×105m\le 5\times 10^5