#K56267. Minimum Steps to Open Chests

    ID: 30161 Type: Default 1000ms 256MiB

Minimum Steps to Open Chests

Minimum Steps to Open Chests

You are given three integers \(N\), \(T\), and \(S\) where:

  • \(N\) is the number of chests that need to be opened,
  • \(T\) is the number of available tools,
  • \(S\) is the number of special keys.

The rule is that if the total number of keys (tools + special keys) is at least \(N\) (i.e. \(T+S \geq N\)), then every chest can be opened with one step each, resulting in \(N\) steps. Otherwise, you can only open as many chests as you have keys, i.e. \(T+S\) steps.

Your task is to determine the minimum number of steps required to open all chests for each test case provided.

inputFormat

The first line of input contains an integer (T) denoting the number of test cases. Each of the next (T) lines contains three space-separated integers: (N) (number of chests), (T) (number of tools), and (S) (number of special keys).

outputFormat

For each test case, output a single line containing the minimum number of steps required to open all chests.## sample

6
3 2 1
5 3 2
4 4 0
4 2 3
4 0 0
5 5 0
3

5 4 4 0 5

</p>