| HPI 2024 Novice |
|---|
| Закончено |
While reading about tree trunks in science class, Lazy Bob accidentally read "tree trunks" as "tree trucks" (since after all, 'n' is nothing but a 90° rotated 'c' with a fancy antenna on top). And because Bob likes to think about the limits of things, he thought to himself "Tree trucks? Wow, that's cool. I wonder how tall a tree made out of a specific set of different-length-trucks could be."
Bob has a simple mind. While most trees have branches that stem off of each other in convoluted ways, Bob has always imagined a tree like the average 2nd grader: one truck at the bottom, then a triangle-ish shape of trucks above it, and one final truck at the top.
Here is a formal definition of a truck tree (see image for clarification): A vertical row of at least one truck trucks in the middle; we can imagine infinitesimally small intersection points between the trucks. Every intersection point except the top and the bottom has two equal sized trucks to the left and the right, representing the branches (red, blue, and green trucks in the picture) The order of the lengths of the trucks in the vertical row does not matter, but for the branches, longer branches have to go below shorter branches (as they do in a picture).
Given a set of $$$N$$$ ($$$1 ≤ N ≤ 200,000$$$) trucks, each with length $$$l_i$$$ ($$$1 ≤ l_i ≤ 10^9$$$), help Lazy Bob figure out the tallest valid truck tree he could make. Note that Bob does not need to use all of the trucks, but rather only a subset of his choice.
Line 1: One integer, $$$N$$$ ($$$1 ≤ N ≤ 200,000$$$). Line 2: $$$N$$$ space-separated integers $$$l_1,l_2,...,l_n$$$ ($$$1 ≤ l_i ≤ 10^9$$$).
Line 1: One integer, the height of the tallest possible valid trunk tree Bob could make out of his given set of trucks
81 1 2 2 2 3 4 5
12
Lazy Bob can use the 7 trucks (everything except for one truck with length 2):
Use trucks with length 3, 4, and 5 as the vertical ones
Use a pair of trucks with length 2 for the first (bottommost) pair of branches
Use a pair of trucks with length 1 for the second (in this case topmost) pair of branches
It can be shown that no taller valid truck tree can be made from the given set of trucks.
| Название |
|---|


