CF1697A.Parkway Walk

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are walking through a parkway near your house. The parkway has n+1n+1 benches in a row numbered from 11 to n+1n+1 from left to right. The distance between the bench ii and i+1i+1 is aia_i meters.

Initially, you have mm units of energy. To walk 11 meter of distance, you spend 11 unit of your energy. You can't walk if you have no energy. Also, you can restore your energy by sitting on benches (and this is the only way to restore the energy). When you are sitting, you can restore any integer amount of energy you want (if you sit longer, you restore more energy). Note that the amount of your energy can exceed mm.

Your task is to find the minimum amount of energy you have to restore (by sitting on benches) to reach the bench n+1n+1 from the bench 11 (and end your walk).

You have to answer tt independent test cases.

你正在家附近的林荫道上行走。这条林荫道上从左到右依次排列着 n+1n+1 张长椅,编号为 11 到 n+1n+1。第 ii 张长椅与第 i+1i+1 张长椅之间的距离为 aia_i 米。

初始时,你拥有 mm 单位能量。每行走 11 米的距离,你将消耗 11 单位能量。当你能量为 00 时,将无法继续行走。此外,你只能通过坐在长椅上来恢复能量(这是唯一恢复能量的方式)。当你坐在长椅上时,你可以恢复任意整数单位的能量(坐得越久,恢复的能量越多)。注意:你的能量总量可以超过 mm。

你的任务是:求出从第 11 张长椅出发,最终到达第 n+1n+1 张长椅(并结束行走)所需恢复的最小能量总量(即坐在长椅上所恢复的能量总和)。

你需要回答 tt 个相互独立的测试用例。

输入格式

The first line of the input contains one integer tt (1≤t≤1001 \le t \le 100) — the number of test cases. Then tt test cases follow.

The first line of the test case contains two integers nn and mm (1≤n≤1001 \le n \le 100; 1≤m≤1041 \le m \le 10^4).

The second line of the test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1001 \le a_i \le 100), where aia_i is the distance between benches ii and i+1i+1.

输入的第一行包含一个整数 tt(1≤t≤1001 \le t \le 100),表示测试用例的数量。随后是 tt 个测试用例。

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n≤1001 \le n \le 100;1≤m≤1041 \le m \le 10^4)。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1001 \le a_i \le 100),其中 aia_i 表示第 ii 个长椅与第 i+1i+1 个长椅之间的距离。

输出格式

For each test case, print one integer — the minimum amount of energy you have to restore (by sitting on benches) to reach the bench n+1n+1 from the bench 11 (and end your walk) in the corresponding test case.

对于每个测试用例,输出一个整数——即在对应的测试用例中,从长椅 11 出发到达长椅 n+1n+1(并结束行走)所需恢复的最小能量值(通过坐在长椅上恢复)。

输入输出样例

  • 输入#1

    3
    3 1
    1 2 1
    4 5
    3 3 5 2
    5 16
    1 2 3 4 5

    输出#1

    3
    8
    0

说明/提示

In the first test case of the example, you can walk to the bench 22, spending 11 unit of energy, then restore 22 units of energy on the second bench, walk to the bench 33, spending 22 units of energy, restore 11 unit of energy and go to the bench 44.

In the third test case of the example, you have enough energy to just go to the bench 66 without sitting at all.

在示例的第一个测试用例中,你可以步行至长椅 22,消耗 11 单位能量,然后在第二张长椅上恢复 22 单位能量,再步行至长椅 33,消耗 22 单位能量,恢复 11 单位能量,最后前往长椅 44。

在示例的第三个测试用例中,你的能量足够直接前往长椅 66,而无需在任何长椅上休息。

输入解题思路,AI测评打分。不知道怎么写?

首页