Crossing Blocks Problem Code: CROSBLK Codechef Solutions
Crossing Blocks Problem Code: CROSBLKSubmit
Read problem statements in Mandarin, Bengali, Russian, and Vietnamese as well.
Chef is very adventurous, so he asked Bob to give him a task.
Bob gave him a sequence of blocks with heights . Chef is at the first block and he has to reach the -th block using the minimum number of moves to complete the task.
In one move, he can jump from the -th block to the -th block only if the following conditions are satisfied:
- for all (),
You have to find the minimum number of moves Chef needs to perform to reach the last block, or determine that it is impossible.
Input Format
- The first line of the input contains a single integer denoting the number of test cases. The description of test cases follows.
- The first line of each test case contains a single integer .
- The second line contains space-separated integers .
Output Format
For each test case, print a single line containing one integer --- the minimum number of moves or if it is impossible to reach the last block.
Constraints
- for each valid
- the sum of over all test cases does not exceed
Subtasks
Subtask #1 (30 points):
- the sum of over all test cases does not exceed
Subtask #2 (70 points): original constraints
Sample Input 1
2
5
9 15 8 13 8
9
20 16 13 9 17 11 15 8 7
Sample Output 1
-1
4
Explanation
Example case 1: There is no way to move from the first block (with height ) to any other block.
Example case 2: The only sequence of moves is . For example, in the first move, all the heights between and do not exceed , so all conditions are satisfied.
Solution in C++
Comments
Post a Comment