当前位置:网站首页>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;
}边栏推荐
- Okaleido tiger is about to log in to binance NFT in the second round, which has aroused heated discussion in the community
- If the detailed explanation is generated according to the frame code
- Banyan loan,
- Prime factorization -- C (GCC) -- PTA
- Director of meta quest content ecology talks about the original intention of APP lab design
- Six determination methods of Worthington peroxidase activity
- Record the problem of PHP program accessing system files incorrectly
- Using redis C library, the problem of asynchronous memory leakage
- A. Parkway Walk
- Characteristics and determination scheme of Worthington pectinase
猜你喜欢

VR全景制作在家装行业是谈单利器?这是为什么呢?

Learning and understanding of four special data types of redis

On the first day of Shenzhen furniture exhibition, the three highlights of Jin Ke'er booth were unlocked!

次轮Okaleido Tiger即将登录Binance NFT,引发社区热议

Programming implementation of eight queens

Okaleido tiger is about to log in to binance NFT in the second round, which has aroused heated discussion in the community

飞腾腾锐 D2000 荣获数字中国“十大硬核科技”奖

Chapter 4 决策树和随机森林

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

Characteristics and determination scheme of Worthington pectinase
随机推荐
Chapter 5 决策树和随机森林实践
VR全景现在是不是刚需?看完你就明白了
03.获取网页源代码
代码回滚,你真的理解吗?
Have you encountered the situation that CDC reads incomplete MySQL fields? How to deal with it?
Characteristics and experimental suggestions of abbkine abfluor 488 cell apoptosis detection kit
Function pointer and callback function
03. Get the web page source code
Review in the sixth week
C # using sqlsugar updatable system to report invalid numbers, how to solve it? Ask for guidance!
Solution to Chinese garbled code in console header after idea connects to database to query data
Maximum subarray cumulative sum less than or equal to K
768. Block II greed that can complete sorting at most
On the first day of Shenzhen furniture exhibition, the three highlights of Jin Ke'er booth were unlocked!
Realization of regular hexagon map with two-dimensional array of unity
Do you really understand code rollback?
Record the problem of PHP program accessing system files incorrectly
明汯投资裘慧明:长期优异超额的背后考验的是团队的投研能力和策略的完整性
Csu18m91 is used as the master controller of the intelligent scale scheme
Basic concept and essence of Architecture