当前位置:网站首页>A. Parkway Walk
A. Parkway Walk
2022-07-27 02:30:00 【Felven】
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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 aiai 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.
Input
The first line of the input contains one integer tt (1≤t≤1001≤t≤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≤n≤100; 1≤m≤1041≤m≤104).
The second line of the test case contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1001≤ai≤100), where aiai is the distance between benches ii and i+1i+1.
Output
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.
Example
input
Copy
3 3 1 1 2 1 4 5 3 3 5 2 5 16 1 2 3 4 5
output
Copy
3 8 0
Note
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.
解题说明:水题,直接累加后减去原始值即可,如果大于就需要补充能量,否则不需要补充。
#include<stdio.h>
int main()
{
int x;
scanf("%d", &x);
while (x--)
{
int y, z, p, sum = 0;
scanf("%d%d", &y, &z);
for (int i = 0; i<y; i++)
{
scanf("%d", &p);
sum = sum + p;
}
if (sum > z)
{
printf("%d\n", sum - z);
}
else
{
printf("0\n");
}
}
return 0;
}边栏推荐
- Is Jiufang intelligent investment a regular company? Talk about Jiufang intelligent investment
- 03.获取网页源代码
- Record the problem of PHP program accessing system files incorrectly
- Briefly sort out the dualpivotquicksort
- 03. Get the web page source code
- Mysql database related operations
- Typescript TS basic knowledge interface, generics
- Banyan loan,
- Vector to SVG method
- The fifth strong network cup national network security challenge Title reappearance (with title attachment, detailed explanation)
猜你喜欢

Contour detection based on OpenCV (1)

Plato farm brings a new experience to community users through the LAAS protocol elephant swap

Introduction to database - a brief introduction to MySQL

connman介绍

Six determination methods of Worthington peroxidase activity

Connman introduction

If the detailed explanation is generated according to the frame code

Worthington papain dissociation system solution

MySQL has a nonexistent error

Message queue learning -- Concepts
随机推荐
第五届强网杯全国网络安全挑战赛 题目复现(有题目附件,详解)
jmeter接口测试(登录、注册)
开机启动流程及营救模式
03. Get the web page source code
On the first day of Shenzhen furniture exhibition, the three highlights of Jin Ke'er booth were unlocked!
Cocos game practice-04-collision detection and NPC rendering
connman介绍
Plato farm is expected to further expand its ecosystem through elephant swap
DTS is equipped with a new self-developed kernel, which breaks through the key technology of the three center architecture of the two places Tencent cloud database
【无标题】JDBC连接数据库读超时
Do you really understand code rollback?
Contour detection based on OpenCV (2)
The fifth strong network cup national network security challenge Title reappearance (with title attachment, detailed explanation)
Reading notes of Kazuo Inamori's advice to young people
The new version of Alibaba Seata finally solves the idempotence, suspension and empty rollback problems of TCC mode
使用redis c库,异步内存泄露的问题
Use websocket to realize a web version of chat room (fishing is more hidden)
Typescript TS basic knowledge interface, generics
注释有点好玩哦
Food chain (day 79)