#BS0000316. Vượt qua bẫy (A Game with Traps)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Vượt qua bẫy (A Game with Traps)
A Game with Traps
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
In a game you command soldiers. Soldier has agility . The level is the segment from position to ; initially you and the soldiers are at .
There are traps. Trap is located at , has danger level , and can be disabled instantly when you are at . A soldier with agility below cannot enter while this trap is active. Traps do not affect you.
Before starting, choose a squad. In one second, you can move one unit in either direction, alone or with the entire squad if you share its position. The squad cannot move independently. Disabling a trap takes no time. All positions remain integers after each action.
Find the largest squad that you can bring safely from to within seconds.
Input
- The first line contains four integers : the soldier count, number of interior integer positions, trap count and time limit in seconds.
- The second line contains integers , the soldiers’ agility values.
- Each of the next lines contains three integers describing trap .
Output
Print one integer: the maximum number of soldiers that can reach the destination safely, or 0 if none can.
Subtasks
- Subtask 1 (20 points): ; ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (50 points): ; ; ; .
Examples
Input 1
5 6 4 14
1 2 3 4 5
1 5 2
1 2 5
2 3 5
3 5 3
Output 1
3
Explanation
Choose soldiers with agility 3, 4 and 5. Walk alone from 0 to 3, disable the two level-5 traps upon reaching positions 2 and 3, and return to 0. This takes 6 seconds; the squad then walks to 7 in 7 seconds, for a total of 13. A squad of four contains someone with agility at most 2. Dangerous intervals then cover positions 1 through 5; traversing these intervals alone and returning requires at least 10 extra steps in addition to the 7 squad steps. The total of at least 17 exceeds 14.