Φ²
Time limit1sMemory limit1024 MB
Each day, microorganisms in a line absorb adjacent neighbors no bigger than themselves, front to back. Output the survivor's final size and starting index.
- Level
Medium6 of 10
- Topics
- Simulation, Linked list, Implementation
- Solved
- No attempts yet
Problem
Sunah is studying a certain microorganism. While researching it, Sunah found that when several of these microorganisms are arranged in a line, they absorb each other according to the following rules until only one remains.
- Once per day, starting from the microorganism at the front of the line, each microorganism in turn absorbs all adjacent microorganisms that are smaller than or equal to its own size. When it absorbs another microorganism, its size increases by the size of the absorbed one.
- An absorbed microorganism disappears and cannot act. For example, if there are three microorganisms with sizes , , and , then is absorbed by before its turn comes, so after one day the remaining sizes are and .
- A microorganism absorbs everything it will absorb that day in a single action. For example, if there are three microorganisms with sizes , , and , and it is 's turn, then absorbs only . It is impossible for to absorb the same day after becoming . So after one day the remaining sizes are and .
Input
The first line contains the number of microorganisms . ()
The second line contains integers separated by spaces, where is the initial size of the -th microorganism. Each initial size is an integer from to , inclusive. No two microorganisms have the same initial size.
Output
Print the final size of the microorganism that remains at the end on the first line.
Print the initial position of that microorganism on the second line.