当前位置:网站首页>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;
}边栏推荐
- Learning and understanding of four special data types of redis
- Leetcode- > dichotomy (III)
- Characteristics and experimental suggestions of abbkine abfluor 488 cell apoptosis detection kit
- 榕树贷款C语言结构体里的成员数组和指针
- Characteristics and determination scheme of Worthington pectinase
- Digital analog 1232
- Chapter 4 决策树和随机森林
- Characteristics and determination scheme of Worthington pectinase
- NLP hotspots from ACL 2022 onsite experience
- Number of 0 at the end of factorial
猜你喜欢

About the solution of using hyperbeach to appear /bin/sh: 1: packr2: not found

NLP hotspots from ACL 2022 onsite experience

分享当下人生——一个高中毕业生在中央电视台的六星期实习经历

Network security / penetration testing tool awvs14.9 download / tutorial / installation tutorial

Duplicate disc: what are the basic attributes of an image? What do you know about images? What are the parameters of the image

Practical application of digital twins: smart city project construction solution

Share the current life -- a six week internship experience of a high school graduate in CCTV

Redis spike case, learn from Shang Silicon Valley teacher in station B

关于使用hyperbeach出现/bin/sh: 1: packr2: not found的解决方案

函数指针与回调函数
随机推荐
Leetcode- > dichotomy (III)
百融榕树数据分析拆解方法
Number of 0 at the end of factorial
这个FlinkCDC会监控数据库中所有的表?还是指定的表呢?我看后台日志,他是监控了所有表,如果监控
Csu18m91 is used as the master controller of the intelligent scale scheme
MySQL has a nonexistent error
Kettle读取按行分割的文件
Do you really understand code rollback?
Regression testing: meaning, challenges, best practices and tools
Connman introduction
Introduction to redis
About the solution of using hyperbeach to appear /bin/sh: 1: packr2: not found
Textbox in easyUI inserts content at the cursor position
Process analysis of object creation
在typora中插入图片和视频
Tool class of localdatetime sorted out by yourself
[Android synopsis] kotlin multithreaded programming (I)
数字孪生应用及意义对电力的主要作用,概念价值。
Binary tree (day 82)
GetObject call timing of factorybean