#P9494. 「SFCOI-3」进行一个走的行
「SFCOI-3」进行一个走的行
Background
Announcement: Note that cases with may occur; in such cases, the operation is invalid.
Xiao L is keen on walking.
Problem Description
Xiao L arrives at a tourist attraction and wants to walk along the main road there.
There are several key points on the main road. He can model them as a sequence of length . Each is a triple , meaning:
- If , it represents a scenic spot that requires buying a ticket to enter. The ticket costs coins, and after the visit he will gain happiness.
- If , it represents a gift distribution point. If the total face value of the coins he holds is and satisfies , he can claim one gift and will gain happiness.
He plans to walk along this main road times. Each time, he is given the starting point and the ending point . At the beginning, the total face value of the coins he holds is , and his initial happiness is .
He will start from and pass through from left to right. He will do the following:
- If , if he still has coins left after paying the current ticket fee, he will visit this scenic spot.
- If , if possible, he will claim one gift.
Please help him quickly compute his happiness after each walk ends.
Input Format
The first line contains two integers .
The next lines: the -th line contains three integers .
The next lines: each line contains three integers , describing one query.
Output Format
Output lines, each containing one integer, representing the happiness after the walk ends.
4 10
1 1 4
5 -1 4
1 9 19
8 -1 10
1 1 11
2 2 4
3 3 5
4 4 14
1 2 1
2 3 9
3 4 1
1 3 9
2 4 8
1 4 10
0
0
19
10
4
23
19
23
23
23
Hint
This problem uses bundled testdata.
- Subtask 1 (10 pts): .
- Subtask 2 (10 pts): .
- Subtask 3 (20 pts): .
- Subtask 4 (10 pts): , Property A.
- Subtask 5 (20 pts): .
- Subtask 6 (10 pts): The testdata is generated randomly within the constraints, Property B.
- Subtask 7 (20 pts): No special restrictions.
Property A: , or , .
Property B: When , .
For of the testdata:
- .
- , or .
- .
- , .
Translated by ChatGPT 5