Minimum moves
Practice
2.4 (27 votes)
Basic programming
Problem
47% Success 10247 Attempts 10 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You want to reach a destination but you decide that you can make moves in two directions only. If you are at position \((x,\ y)\), then you can move to \((x+1,\ y+1)\) or \((x+1,\ y)\). You must start your journey from \((0,\ 0)\) and your destination is \((X,\ Y)\). Your task is to find the minimum number of moves that you require to reach the destination or if he cannot reach the destination.
Input format
- The first line contains an integer \(T\) denoting the number of test cases.
- For each test case, there is a single line consisting of two integers \(X\) and \(Y\).
Output format
For each test case, print a single line denoting the minimum number of moves that you must take to reach the destination. Print -1 if you cannot reach the destination.
Constraints
\(1\leq T \leq 1000\)
\(|X|,|Y|\leq1e9\)
Submissions
Please login to view your submissions
Similar Problems
Points:10
51 votes
Tags:
Basic ProgrammingBasics of ImplementationEasyImplementation
Points:10
29 votes
Tags:
Basic ProgrammingC++
3.The Dice
Points:10
83 votes
Tags:
Basic ProgrammingBasics of ImplementationEasyImplementation
Editorial