#P12196. [NOISG 2025 Prelim] Lasers 2

[NOISG 2025 Prelim] Lasers 2

题目描述

Pavement has purchased a laser toy from Gohcart (who originally bought it from Rar the Cat). The toy features a grid of hh rows and ww columns. The rows of the grid are numbered 11 to hh from top to bottom, and the columns of the grid are numbered 11 to ww from left to right.

Each row contains exactly one locked sliding wall. Initially, the wall in the ii-th row spans columns l[i]l[i] to r[i]r[i] (11-indexed), and can be unlocked for c[i]c[i] dollars. Once unlocked, it can be slid horizontally to any position along the ii-th row, as long as it is aligned to the edges of the grid. No part of the wall can leave the left or right edges of the toy.

Each column contains a downward-facing laser positioned at the top of the column. If any sliding wall is contained in the ii-th column, it will block the path of the laser in the ii-th column.

A possible toy with h=3h = 3 and w=10w = 10 is depicted in the diagram below:

Given a total budget of kk dollars, Pavement aims to maximise the number of lasers that are not blocked after optimally unlocking and sliding the walls. Determine the maximum number of unblocked lasers he can achieve.

输入格式

Your program must read from standard input.

The first line of input contains three space-separated integers h,wh, w and kk, describing the number of rows, the number of columns and the budget, respectively.

The next hh lines of input each contain three space-separated integers. The ii-th of these lines contains l[i],r[i]l[i], r[i], and c[i]c[i], describing the sliding wall in the ii-th row.

输出格式

Your program must print to standard output.

Output a single integer, the maximum number of unblocked lasers achievable.

3 10 10
2 5 9
1 3 1
4 7 10
6
10 10 50
8 8 0
3 3 0
6 6 2
7 7 9
1 1 50
5 5 21
6 6 4
10 10 4
10 10 3
10 10 3
9
4 17 0
2 4 1000000000
6 9 1000000000
8 13 1000000000
15 16 1000000000
4

提示

Subtasks

For all testcases, the input will satisfy the following bounds:

  • 1h,w20001 \leq h, w \leq 2000
  • 0k1090 \leq k \leq 10^9
  • 1l[i]r[i]w1 \leq l[i] \leq r[i] \leq w for all 1ih1 \leq i \leq h
  • 0c[i]1090 \leq c[i] \leq 10^9 for all 1ih1 \leq i \leq h

Your program will be tested on input instances that satisfy the following restrictions:

Subtask Marks Additional constraints
00 Sample test cases
11 66 k=0,c[i]=109k = 0, c[i] = 10^9
22 99 l[i]=r[i]l[i] = r[i]
33 1010 h,w18h, w \leq 18
44 77 h,w100,k2000h, w \leq 100, k \leq 2000
55 1515 h,w100h, w \leq 100
66 2323 h,w500h, w \leq 500
77 88 r[1]l[1]=r[2]l[2]==r[h]l[h]r[1] − l[1] = r[2] − l[2] = \ldots = r[h] − l[h]
88 2222 No additional constraints

Sample Test Case 1 Explanation

This test case is valid for subtasks 3,4,5,63, 4, 5, 6, and 88.

The laser toy in the above figure corresponds to this test case. Pavement can unlock the first and second sliding walls for a total cost of 9+1=109 + 1 = 10 dollars. He can then slide the first sliding wall such that it spans columns 44 to 77, and slide the second sliding wall to span columns 55 to 77.

This leaves 66 lasers (in columns 1,2,3,8,91, 2, 3, 8, 9, and 1010) unblocked, which is the maximum possible.

Sample Test Case 2 Explanation

This test case is valid for subtasks 22 to 88.

Sample Test Case 3 Explanation

This test case is valid for subtasks 1,3,4,5,61, 3, 4, 5, 6, and 88.