Codeforces 1099 A. Snowball-暴力(Codeforces Round #530 (Div. 2))

A. Snowball

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard 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 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.

Input

First line contains two integers ww and hh — initial weight and height of the snowball (0w1000≤w≤100; 1h1001≤h≤100).

Second line contains two integers u1u1 and d1d1 — weight and height of the first stone (0u11000≤u1≤100; 1d1h1≤d1≤h).

Third line contains two integers u2u2 and d2d2 — weight and heigth of the second stone (0u21000≤u2≤100; 1d2h1≤d2≤h; d1d2d1≠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
Copy
4 3
1 1
1 2
output
Copy
8
input
Copy
4 3
9 2
0 1
output
Copy
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 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 }

猜你喜欢

转载自www.cnblogs.com/ZERO-/p/10263686.html