Problem D
Flipping Patties

Business is booming at Big Bill’s Burger Shack. Bill sells
the most convenient, customizable burger in town. Using either
the shack’s website or mobile application, customers can
request patties that are prepared precisely to the
second. The
Big Bill is a talented grill cook, and he only hires talented grill cooks. In a given second, a grill cook can use a hand to do at most one of the following:
-
place a new patty on the grill,
-
flip a patty that is already on the grill,
-
remove a patty from the grill to serve it to a customer, or
-
do nothing.
Each grill cook has two hands, so they can do up to two of the above actions in a second.
When a patty is placed or flipped on the grill, the side on
the grill immediately starts cooking. For example, if a patty
is placed on the grill at
These customers are demanding — they want to be served
exactly at
Input
The first line contains a single integer
Output
Output a single integer, the minimum number of cooks needed to prepare all of the orders.
Sample Input 1 | Sample Output 1 |
---|---|
3 1 4 2 5 7 14 |
1 |
Sample Input 2 | Sample Output 2 |
---|---|
4 2 4 2 4 2 4 2 4 |
2 |