GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Saturday 20 August 2022

[Solution] Crossmarket Codeforces Solution| Codeforces Solution



A. Crossmarket
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Stanley and Megan decided to shop in the "Crossmarket" grocery store, which can be represented as a matrix with n rows and m columns.

Stanley and Megan can move to an adjacent cell using 1 unit of power. To speed up the shopping process, Megan brought her portals with her, and she leaves one in each cell she visits (if there is no portal yet). If a person (Stanley or Megan) is in a cell with a portal, that person can use 1 unit of power to teleport to any other cell with a portal, including Megan's starting cell.

They decided to split up: Stanley will go from the upper-left cell (cell with coordinates (1,1)) to the lower-right cell (cell with coordinates (n,m)), whilst Megan needs to get from the lower-left cell (cell with coordinates (n,1)) to the upper-right cell (cell with coordinates (1,m)).

What is the minimum total energy needed for them both to do that?

Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇

Note that they can choose the time they move. Time does not affect energy.

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1t1000). Description of the test cases follows.

The only line in the test case contains two integers n and m (1n,m105).

Output

For each test case print a single integer on a new line – the answer.

No comments:

Post a Comment