SalesforceOA #35
Plan Cuts
Estimated MediumJudge-ready
Topics (AI-labelled)GreedyTwo Pointers
A rod already has the lengths of all its final segments marked in order. The machine can only cut an existing rod of length at least minLength, and each cut splits it into two rods at one mark that has not been cut yet. Determine whether there is an order that completes the cuts at all marks.
Input
The input gives n, the n segment lengths, and minLength. The original has no numeric bounds, and the extra ranges in the catalog have no basis in the original text; this site adds 2≤n≤200000, each segment 1..10^9, 1≤minLength≤10^18. n≥2 guarantees that there really is a last cut.
Output
Output Possible if it can be done, otherwise Impossible.
Example 1
Input:
4
3 5 4 3
9
Output:
Possible
Example 2
Input:
3
4 2 3
7
Output:
Impossible
Example 3
Input:
3
4 3 2
7
Output:
Possible
Example notes
The outputs of the three public examples are, in order: Possible; Impossible; Possible. They have been checked by independent enumeration or direct simulation.
Editorial
Loading solution…