Planets of Two Dimensions
Time limit1sMemory limit1024 MB
Given n planets in dimension X and m in dimension Y, find the longest trip that visits no planet twice and never visits two same-dimension planets in a row.
- Level
Easy2 of 10
- Topics
- Math
- Solved
- No attempts yet
Problem
Rick and Morty plan a trip through the planets of two recently discovered dimensions. The dimensions have no names yet, so we call them and . Dimension has planets, and dimension has planets. Rick does not want Morty to plan the adventure, but since Morty's birthday is soon, Rick agrees to give in once. Morty may choose which planets to visit and in what order. He does not want to visit the same planet twice. He also does not want to visit two planets from the same dimension in a row. The trip may start and end on any planet of either dimension. Rick does not explain that these conditions sometimes make it impossible to visit all planets. Find the maximum number of planets that can be visited without breaking Morty's conditions.
Input
The first line contains two integers and , separated by a space, the number of planets in dimensions and ().
Output
Print the answer to the problem on a single line.