Great Comebacks
Time limit2sMemory limit1024 MB
Given the final powerful strike counts of Thor and Hulk, find the largest possible number of times a trailing fighter goes on to lead.
- Level
Medium4 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Statement
Thor and Hulk fight to the death. One powerful strike follows another. The crowd is thrilled!
The Grandmaster watches the fight. He does not root for either fighter. He cares about the spectacle, so after the fight he wants to rate how exciting it was. He counts every powerful strike by each fighter, then counts the comebacks during the fight. A comeback happens when a fighter who was trailing in the count of powerful strikes goes on to lead.
The Grandmaster kept only the final score and cannot reconstruct the number of comebacks. He liked the fight so much that he assumes the number of comebacks was the largest possible. Given the final score, find that maximum number of comebacks.
Input
A single line with two integers and separated by a colon (:). is the number of powerful strikes by Thor, and is the number of powerful strikes by Hulk ().
Output
Print one integer, the largest possible number of comebacks in the fight.
Hint
In the first example, Thor gave Hulk no chance to strike, so no comebacks are possible.
In the second example, Hulk strikes first, then takes two strikes from Thor, and then finishes him with six strikes in a row. So Hulk leads first, Thor makes a comeback, and then Hulk takes the lead back.