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 hh and it has weight ww. Each second the following sequence of events happens: snowball's weights increases by ii, where ii — 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 u1u1 and is located at height d1d1, the second one — u2u2 and d2d2respectively. 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.
First line contains two integers ww and hh — initial weight and height of the snowball (0≤w≤1000≤w≤100; 1≤h≤1001≤h≤100).
Second line contains two integers u1u1 and d1d1 — weight and height of the first stone (0≤u1≤1000≤u1≤100; 1≤d1≤h1≤d1≤h).
Third line contains two integers u2u2 and d2d2 — weight and heigth of the second stone (0≤u2≤1000≤u2≤100; 1≤d2≤h1≤d2≤h; d1≠d2d1≠d2). Notice that stones always have different heights.
Output a single integer — final weight of the snowball after it reaches height 0.
4 3 1 1 1 2
8
4 3 9 2 0 1
1
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 to 8.
- 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 to 8.
- 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.
题意就是滚雪球,每下降1米,就增加当前高度的重量,如果碰到石头就会减掉石头重量的雪,如果减位负数就是0,然后从0也可以往下滚然后增加。输出最后重量。
代码:
1 //A 2 #include<bits/stdc++.h> 3 using namespace std; 4 5 int main() 6 { 7 int w,h,w1,h1,w2,h2; 8 cin>>w>>h>>w1>>h1>>w2>>h2; 9 for(int i=h;i>=0;i--){ 10 w+=i; 11 if(i==h1){ 12 w-=w1; 13 if(w<0) w=0; 14 } 15 else if(i==h2){ 16 w-=w2; 17 if(w<0) w=0; 18 } 19 } 20 cout<<w<<endl; 21 }