#K6891. Hexaphone Melody Problem

    ID: 32969 Type: Default 1000ms 256MiB

Hexaphone Melody Problem

Hexaphone Melody Problem

You are given two integers (M) and (K) where (M) represents the total number of different musical notes and (K) is the maximum allowed number of note changes. Starting from any note, you must determine the minimum length of a melody (i.e. the minimum number of notes played) such that the melody does not exceed the allowed (K) changes. Note that if no change is allowed (i.e. (K = 0)), only one note can be played. Otherwise, the answer is given by ( \min(M, K+1) ).

For example, if (M = 5) and (K = 2), the minimum melody length will be 3, because you can play a maximum of 3 distinct notes before surpassing the allowed 2 changes.

inputFormat

The first line contains an integer (T) ((1 \leq T \leq 10^4)), the number of test cases. Each of the following (T) lines contains two space-separated integers (M) and (K) ((1 \leq M \leq 10^9, 0 \leq K \leq 10^9)).

outputFormat

For each test case, print the minimum length of the melody that can be played without exceeding (K) changes. Each answer should be printed on a new line.## sample

3
5 2
7 3
4 0
3

4 1

</p>