Fireworks
InterviewTime limit1sMemory limit1024 MB
Given firecracker brilliances and a threshold K, find the most shows you can build from single or paired firecrackers, each at least K and in non-decreasing order.
- Level
Medium5 of 10
- Topics
- Greedy, Sorting, Two pointers
- Solved
- No attempts yet
Problem
INU Code Festival ends with a fireworks show. Gwangjae is in charge of this year's fireworks.
Someone bought up all the firecrackers, so the show has to be built from the remaining firecrackers.
Each firecracker has an integer that gives its brilliance. Arrange the show so that it satisfies the following rules. You do not have to use every firecracker.
- The brilliance of the first show must be at least .
- The brilliance of each show is not less than the brilliance of the previous show.
- For safety, you can set off only 1 or 2 firecrackers at a time. If you set off 2 at once, the brilliance is the sum of the two.
For example, suppose the remaining firecrackers have brilliance and the first show must have brilliance at least . Then the show can proceed as follows while satisfying the rules.
This gives 4 shows. No sequence can satisfy the rules with more shows.
If the remaining firecrackers have brilliance and the first show must have brilliance at least , the show cannot satisfy the rules.
Students enjoy the show more when there are more shows. Help Gwangjae build as many shows as possible.
If at least one show can be held, print the maximum number of shows. If no show can be held, print .
Input
The first line contains and . (, , is an integer.)
The second line contains integers separated by spaces, the brilliance of each firecracker. ()
Output
Print the maximum number of shows that can be held. If no show can be held, print .