当前位置:网站首页>A. Parkway Walk
A. Parkway Walk
2022-07-27 04:00: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.
Problem solving instructions : Water problem , After direct accumulation, subtract the original value , If it is larger than, you need to supplement energy , Otherwise, there is no need to supplement .
#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;
}边栏推荐
- Six determination methods of Worthington peroxidase activity
- Okaleido tiger is about to log in to binance NFT in the second round, which has aroused heated discussion in the community
- The job created by flinksqlclient will disappear after the restart of Flink. Is there any way?
- 安装umi4阻碍一天的问题解决了
- Okaleido tiger is about to log in to binance NFT in the second round, which has aroused heated discussion in the community
- Csu18m91 is used as the master controller of the intelligent scale scheme
- C# 使用SqlSugar Updateable系统报错无效数字,如何解决?求指导!
- Design method and test method of APP interface use case
- A. YES or YES?
- Do you really understand code rollback?
猜你喜欢

477-82(236、61、47、74、240、93)

Kettle reads file split by line

FastBoot brush machine

VR全景现在是不是刚需?看完你就明白了

Bean Validation原理篇--07

Program to change the priority of the process in LabVIEW

NLP hotspots from ACL 2022 onsite experience

GetObject call timing of factorybean

Programming implementation of eight queens

Application, addition and deletion of B-tree
随机推荐
阿里云服务器域名加端口网页不能访问问题记录
[Yugong series] July 2022 go teaching course 018 switch of branch structure
ZJCTF_ login
Worthington papain dissociation system solution
Alibaba cloud server domain name and port web page cannot access the problem record
Learning and understanding of four special data types of redis
九方智投是正规公司吗?一起聊聊九方智投
03.获取网页源代码
Do you really understand code rollback?
C语言入门实战(12):求自然常数e的值
J-3-point practice in the second game of 2022 Niuke multi school
GetObject call timing of factorybean
大家有遇到CDC读MySQL字段不全的情况吗?怎么处理的?
Threads and processes
[tree chain dissection] 2022 Hangzhou Electric Multi school 21001 static query on tree
Binary tree (day 82)
Bean Validation原理篇--07
Is it safe for tongdaxin to open an account
【无标题】
NFT数字藏品系统开发:老牌文学杂志玩起新潮数字藏品