A. Snowball

题目链接:https://codeforces.com/contest/1099/problem/A
A. Snowball
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Today’s morning was exceptionally snowy. Meshanya decided to go outside and noticed a huge snowball rolling down the mountain! Luckily, there are two stones on that mountain.
Initially, snowball is at height h and it has weight w. Each second the following sequence of events happens: snowball’s weights increases by i, where i — is the current height of snowball, then snowball hits the stone (if it’s present at the current height), then snowball moves one meter down. If the snowball reaches height zero, it stops.

There are exactly two stones on the mountain. First stone has weight u1 and is located at height d1, the second one — u2 and d2 respectively. When the snowball hits either of two stones, it loses weight equal to the weight of that stone. If after this snowball has negative weight, then its weight becomes zero, but the snowball continues moving as before.

Find the weight of the snowball when it stops moving, that is, it reaches height 0.
Input
First line contains two integers w and h — initial weight and height of the snowball (0≤w≤100; 1≤h≤100).
Second line contains two integers u1 and d1 — weight and height of the first stone (0≤u1≤100; 1≤d1≤h).
Third line contains two integers u2 and d2 — weight and heigth of the second stone (0≤u2≤100; 1≤d2≤h; d1≠d2). Notice that stones always have different heights.
Output
Output a single integer — final weight of the snowball after it reaches height 0.
Examples
input
4 3
1 1
1 2
output
8
input
4 3
9 2
0 1
output
1
Note
In the first example, initially a snowball of weight 4 is located at a height of 3, there are two stones of weight 1, at a height of 1 and 2, respectively. The following events occur sequentially:
The weight of the snowball increases by 3 (current height), becomes equal to 7.
The snowball moves one meter down, the current height becomes equal to 2.
The weight of the snowball increases by 2 (current height), becomes equal to 9.
The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to8.
The snowball moves one meter down, the current height becomes equal to 1.
The weight of the snowball increases by 1 (current height), becomes equal to 9.
The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to8.
The snowball moves one meter down, the current height becomes equal to 0.
Thus, at the end the weight of the snowball is equal to 8.

水题
最初,雪球在高度h,它有重量w。每一秒发生以下事件序列:雪球的重量增加i,其中i - 是当前的雪球高度,然后雪球击中石头(如果它出现在当前高度),则雪球向下移动一米。如果雪球达到零高度,它就会停止。
山上有两块石头。第一块石头的重量为u1,位于高度d1,第二块石头分别为u2和d2。当雪球击中两块石头中的任何一块时,它的重量就会减去相当于该石块重量的重量。如果在此雪球具有负重量之后,其重量变为零,但雪球继续像以前一样移动。
找到雪球停止移动时的重量,即达到高度0。

#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
	int a,b,c,d,e,f;
	scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
	int g=b;
	for(int i=g;i>0;i--)
	{
		a+=i;
		if(i == d)
		{
			a-=c;
		}
		if(a<0)
		{
			a=0;
		 }
		 if(i == f)
		 {
		 	a-=e;
		 }
		 if(a<0)
		 {
		 	a=0;
		 }
	}
	printf("%d\n",a);
	return 0;
 }
全部评论

相关推荐

明天不下雨了:我靠2022了都去字节了还什么读研我教你****:你好,本人985电子科大在读研一,本科西南大学(211)我在字节跳动实习过。对您的岗位很感兴趣,希望获得一次投递机会。
点赞 评论 收藏
分享
01-14 15:08
东南大学 Java
点赞 评论 收藏
分享
上去投简历,什么的都准备好了,但是就是反馈率很低,处理的非常慢。而且还卖我的信息,有些公司没投就直接电话找我。真成失联招聘了?
Ethan伊森:真的,虽然天天看到吐槽boss,但是boss一周就约了好几个面试,hr交流反馈都很及时,智联有那个一键投简历,投的比boss多得多,却一个联系约面的都没有
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务