CF1875A.Jellyfish and Undertale

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Flowey has planted a bomb in Snowdin!

The bomb has a timer that is initially set to bb . Every second, the timer will decrease by 11 . When the timer reaches 00 , the bomb will explode! To give the residents of Snowdin enough time to evacuate, you will need to delay the bomb from exploding for as long as possible.

You have nn tools. Each tool can only be used at most once. If you use the ii -th tool, the timer will increase by xix_i . However, if the timer is changed to an integer larger than aa , the timer will be set to aa due to a bug.

More specifically, the following events will happen every second in the following order:

  1. You will choose some (possibly none) of your tools that have not been used before. If you choose the ii -th tool, and the bomb's timer is currently set to cc , the timer will be changed to min(c+xi,a)\min(c + x_i, a) .
  2. The timer decreases by 11 .
  3. If the timer reaches 00 , the bomb explodes.

Jellyfish now wants to know the maximum time in seconds until the bomb explodes if the tools are used optimally.

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt ( 1t20001 \leq t \leq 2000 ). The description of the test cases follows.

The first line of each test case contains three integers aa , bb and nn ( 1ba1091 \leq b \leq a \leq 10^9 , 1n1001 \leq n \leq 100 ) — the maximum value of the bomb's timer, the initial value of the timer of the bomb and the number of tools.

The second line of each test contains nn integers x1,x2,,xnx_1, x_2, \dots, x_n ( 1xi1091 \leq x_i \leq 10^9 ) — the number the timer can increase by using the ii -th tool.

Note that the sum of nn over all test cases is not bounded.

输出格式

For each test case, output a single integer — the maximum time in seconds until the bomb explodes.

输入输出样例

  • 输入#1

    2
    5 3 3
    1 1 7
    7 1 5
    1 2 5 6 8

    输出#1

    9
    21

说明/提示

Let cc denote the value of the bomb's timer. In the first test case:

  • Second 11 : choose tool 11 and 22 at this second, then c=5c=5 ; the timer decreases by 11 , then c=4c=4 .
  • Second 22 : the timer decreases by 11 , then c=3c=3 .
  • Second 33 : the timer decreases by 11 , then c=2c=2 .
  • Second 44 : the timer decreases by 11 , then c=1c=1 .
  • Second 55 : choose tool 33 , then c=5c=5 ; the timer decreases by 11 , then c=4c=4 .
  • Second 66 : the timer decreases by 11 , then c=3c=3 .
  • Second 77 : the timer decreases by 11 , then c=2c=2 .
  • Second 88 : the timer decreases by 11 , then c=1c=1 .
  • Second 99 : the timer decreases by 11 , then c=0c=0 . The bomb explodes.

It can be proved that there is no way to use the tools such that the bomb explodes after more than 99 seconds.

首页