Table of Contents

## Crossmarket solution codeforces

**Crossmarket solution codeforces** – 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Â 11Â 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Â 11Â unit of power to teleport to any other cell with a portal, including Megan’s starting cell.

## [Solution] Crossmarket solution codeforces

They decided to split up: Stanley will go from the upper-left cell (cell with coordinatesÂ (1,1)(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Â (đť‘›,1)(n,1)) to the upper-right cell (cell with coordinatesÂ (1,đť‘š)(1,m)).

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

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

Each test contains multiple test cases. The first line contains the number of test casesÂ đť‘ˇtÂ (1â‰¤đť‘ˇâ‰¤10001â‰¤tâ‰¤1000). Description of the test cases follows.

The only line in the test case contains two integersÂ đť‘›nÂ andÂ đť‘šmÂ (1â‰¤đť‘›,đť‘šâ‰¤1051â‰¤n,mâ‰¤105).

## [Solution] Crossmarket solution codeforces

For each test case print a single integer on a new line â€“ the answer.

15 15 0 299998 340 5 5

## [Solution] Crossmarket solution codeforces

In the first test case they can stick to the following plan:

- Megan (red circle) moves to the cellÂ (7,3)(7,3). Then she goes to the cellÂ (1,3)(1,3), and Stanley (blue circle) does the same.
- Stanley uses the portal in that cell (cells with portals are grey) to get to the cellÂ (7,3)(7,3). Then he moves to his destinationÂ â€” cellÂ (7,5)(7,5).
- Megan also finishes her route and goes to the cellÂ (1,5)(1,5).

The total energy spent isÂ (2+6)+(2+1+2)+(2)=15(2+6)+(2+1+2)+(2)=15, which is our final answer.