#P16796. [蓝桥杯 2026 国 B] 灯带修补
[蓝桥杯 2026 国 B] 灯带修补
Problem Description
Xiaolan has a circular LED strip. There are LEDs on the strip in clockwise order, and the brightness of the -th LED is .
If the absolute difference in brightness between two adjacent LEDs is greater than , then this adjacent pair is called unstable. Since the strip is circular, the -th LED and the -st LED are also adjacent.
Xiaolan may first choose a cut between any two adjacent LEDs to open the circular strip into a line. Then, he will choose a consecutive segment of LEDs in this line to display.
If the chosen display segment contains LEDs, then there are adjacent pairs inside the segment that need to be checked. Xiaolan can repair at most unstable adjacent pairs among them. The display segment is valid if and only if the number of unstable adjacent pairs inside the segment does not exceed .
Please compute, when the cut and the display segment can be chosen freely, the maximum number of consecutive LEDs Xiaolan can display.
Input Format
The first line contains three integers , representing the number of LEDs, the maximum number of unstable adjacent pairs that can be repaired, and the threshold for stable brightness difference.
The second line contains integers , where is the brightness of the -th LED.
Output Format
Output one line containing one integer, which is the maximum number of consecutive LEDs that can be selected.
6 1 3
4 6 10 13 30 31
4
5 0 2
1 10 20 30 40
1
4 3 0
5 100 5 100
4
Hint
Sample Explanation 1
You can cut between the -th and the -st LED. After opening it, choose LEDs to , with brightness values in order.
There are adjacent pairs in this segment: and are stable, and are unstable, and and are stable. After repairing the pair and , you can display consecutive LEDs.
For any segment of consecutive LEDs, the segment will contain at least unstable adjacent pairs, which exceeds , so the answer is .
Sample Explanation 2
As long as the display segment length is at least , an unstable adjacent pair will appear in the segment. Since , no unstable adjacent pairs can be repaired, so at most one LED can be displayed.
Sample Explanation 3
By choosing a suitable cut, you can display all LEDs. After opening it, there are only adjacent pairs in the segment that need to be checked. They are all unstable, but they can all be repaired, so the answer is .
Constraints and Notes for Test Cases
For of the test cases, .
For of the test cases, .
For all test cases, , , , .
Translated by ChatGPT 5