#P4379. [USACO18OPEN] Lemonade Line S
[USACO18OPEN] Lemonade Line S
Description
It is a hot summer day on the farm, and Farmer John is handing out lemonade to his cows! All cows (numbered ) like lemonade, though some like it more than others. Specifically, cow is willing to stand behind at most other cows to get lemonade. All cows are currently out in the field, but as soon as Farmer John rings the cowbell, they will immediately head to the lemonade stand. They will all arrive before Farmer John begins distributing lemonade, and no two cows arrive at the same time. Additionally, when cow arrives, she joins the line if and only if there are at most cows in the line.
Farmer John wants to prepare some amount of lemonade in advance, but he does not want to waste any. The number of cows who line up may depend on their arrival order. Please help him determine, over all possible arrival orders, the minimum possible number of cows that end up in line.
Input Format
The first line contains . The second line contains space-separated integers . The input guarantees , and for each cow , .
Output Format
Output the minimum possible number of cows in line over all possible arrival orders.
5
7 1 400 2 2
3
Hint
For example, it is possible that only three cows end up in the line (which is also the minimum possible). Suppose the cows with and arrive first and wait in line. Then the cow with arrives and leaves because there are already cows in line. Next, two cows with arrive; one stays in line and the other leaves.
Problem setter: Dhruv Rohatgi.
Translated by ChatGPT 5
京公网安备 11011102002149号