CF1036B Diagonal Walking v.2
Description
Mikhail walks on a Cartesian plane. He starts at the point $ (0, 0) $ , and in one move he can go to any of eight adjacent points. For example, if Mikhail is currently at the point $ (0, 0) $ , he can go to any of the following points in one move:
- $ (1, 0) $ ;
- $ (1, 1) $ ;
- $ (0, 1) $ ;
- $ (-1, 1) $ ;
- $ (-1, 0) $ ;
- $ (-1, -1) $ ;
- $ (0, -1) $ ;
- $ (1, -1) $ .
If Mikhail goes from the point $ (x1, y1) $ to the point $ (x2, y2) $ in one move, and $ x1 \ne x2 $ and $ y1 \ne y2 $ , then such a move is called a diagonal move.
Mikhail has $ q $ queries. For the $ i $ -th query Mikhail's target is to go to the point $ (n_i, m_i) $ from the point $ (0, 0) $ in exactly $ k_i $ moves. Among all possible movements he want to choose one with the maximum number of diagonal moves. Your task is to find the maximum number of diagonal moves or find that it is impossible to go from the point $ (0, 0) $ to the point $ (n_i, m_i) $ in $ k_i $ moves.
Note that Mikhail can visit any point any number of times (even the destination point!).
Input Format
N/A
Output Format
N/A
Explanation/Hint
One of the possible answers to the first test case: $ (0, 0) \to (1, 0) \to (1, 1) \to (2, 2) $ .
One of the possible answers to the second test case: $ (0, 0) \to (0, 1) \to (1, 2) \to (0, 3) \to (1, 4) \to (2, 3) \to (3, 2) \to (4, 3) $ .
In the third test case Mikhail cannot reach the point $ (10, 1) $ in 9 moves.