#K38682. Max Consecutive Heads after Flips
Max Consecutive Heads after Flips
Max Consecutive Heads after Flips
You are given two integers n and k. Here, n represents the total number of consecutive heads, and k represents the number of flips you must perform. In each flip, you change one head to a tail. Your task is to compute the maximum number of consecutive heads that can remain after performing exactly k flips.
The answer for a given test case can be computed by the formula:
[ \text{result} = \min(n, n - k)]
Note: It is guaranteed that 0 \le k \le n. For example, if k = 0, no flip is performed and the result is n. If k = n, all heads are flipped, so the result is 0.
inputFormat
The input is read from standard input (stdin) and is in the following format:
- The first line contains an integer T, the number of test cases.
- Each of the next T lines contains two space-separated integers n and k.
outputFormat
For each test case, output a single integer on a new line representing the maximum number of consecutive heads after exactly k flips. The output is written to standard output (stdout).
## sample3
5 1
5 2
5 0
4
3
5
</p>