当前位置:网站首页>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;
}边栏推荐
- 代码回滚,你真的理解吗?
- Basic concept and essence of Architecture
- The fifth strong network cup national network security challenge Title reappearance (with title attachment, detailed explanation)
- [Yugong series] July 2022 go teaching course 018 switch of branch structure
- Chapter 4 decision tree and random forest
- Plato farm has a new way of playing, and the arbitrage eplato has secured super high returns
- jmeter接口测试(登录、注册)
- Chapter 4 决策树和随机森林
- The function and application of lpci-252 universal PCI interface can card
- 04. Detailed steps for installing the simulated browser chromedriver in Google browser
猜你喜欢

connman介绍

阿里云服务器域名加端口网页不能访问问题记录

代码回滚,你真的理解吗?

Briefly sort out the dualpivotquicksort

Installation and use of anti-virus software ClamAV

Basic concept and essence of Architecture

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

Design method and test method of APP interface use case

222. 完全二叉树的节点个数

Smart pointer shared_ ptr、unique_ ptr、weak_ ptr
随机推荐
The job created by flinksqlclient will disappear after the restart of Flink. Is there any way?
Introduction to redis
函数指针与回调函数
Day 28 of leetcode
代码回滚,你真的理解吗?
Data analysis and disassembly method of banyan tree in Bairong
ZJCTF_ login
SkyWalking分布式系统应用程序性能监控工具-中
【安卓小叙】Kotlin多线程编程(一)
NLP hotspots from ACL 2022 onsite experience
It's confirmed that the registration of soft exam in the second half of 2022 will start in August
The function and application of lpci-252 universal PCI interface can card
Six determination methods of Worthington peroxidase activity
一文读懂 | 数据中台如何支撑企业数字化经营
Characteristics and determination scheme of Worthington pectinase
Digital analog 1232
flink cdc 到MySQL8没问题,到MySQL5读有问题,怎么办?
Have you encountered the situation that CDC reads incomplete MySQL fields? How to deal with it?
小于等于K的最大子数组累加和
Principle understanding and application of hash table and consistent hash