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 (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

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也可以往下滚然后增加。输出最后重量。

代码:

 //A
#include<bits/stdc++.h>
using namespace std; int main()
{
int w,h,w1,h1,w2,h2;
cin>>w>>h>>w1>>h1>>w2>>h2;
for(int i=h;i>=;i--){
w+=i;
if(i==h1){
w-=w1;
if(w<) w=;
}
else if(i==h2){
w-=w2;
if(w<) w=;
}
}
cout<<w<<endl;
}

Codeforces 1099 A. Snowball-暴力(Codeforces Round #530 (Div. 2))的更多相关文章

  1. Codeforces 1099 D. Sum in the tree-构造最小点权和有根树 贪心+DFS(Codeforces Round #530 (Div. 2))

    D. Sum in the tree time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  2. Codeforces 1099 C. Postcard-字符串处理(Codeforces Round #530 (Div. 2))

    C. Postcard time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  3. Codeforces 1099 B. Squares and Segments-思维(Codeforces Round #530 (Div. 2))

    B. Squares and Segments time limit per test 1 second memory limit per test 256 megabytes input stand ...

  4. Codeforces Round #530 (Div. 2) A,B,C,D

    A. Snowball 链接:http://codeforces.com/contest/1099/problem/A 思路:模拟 代码: #include<bits/stdc++.h> ...

  5. Codeforces Round #530 (Div. 2) F (树形dp+线段树)

    F. Cookies 链接:http://codeforces.com/contest/1099/problem/F 题意: 给你一棵树,树上有n个节点,每个节点上有ai块饼干,在这个节点上的每块饼干 ...

  6. Codeforces Round #530 (Div. 2):D. Sum in the tree (题解)

    D. Sum in the tree 题目链接:https://codeforces.com/contest/1099/problem/D 题意: 给出一棵树,以及每个点的si,这里的si代表从i号结 ...

  7. Codeforces Round #530 (Div. 2) F 线段树 + 树形dp(自下往上)

    https://codeforces.com/contest/1099/problem/F 题意 一颗n个节点的树上,每个点都有\(x[i]\)个饼干,然后在i节点上吃一个饼干的时间是\(t[i]\) ...

  8. Codeforces Round #530 (Div. 2)F Cookies (树形dp+线段树)

    题:https://codeforces.com/contest/1099/problem/F 题意:给定一个树,每个节点有俩个信息x和t,分别表示这个节点上的饼干个数和先手吃掉这个节点上一个饼干的的 ...

  9. Codeforces Round #530 Div. 1 自闭记

    A:显然应该让未确定的大小尽量大.不知道写了啥就wa了一发. #include<iostream> #include<cstdio> #include<cmath> ...

随机推荐

  1. oracle重新编译失效对像

    重新编译失效对像可执行utlrp.sql文件: SQL> @?/rdbms/admin/utlrp.sql TIMESTAMP --------------------------------- ...

  2. 如何生成Java Key以及sign一个jar

    1. 生成Java Key: keytool -genkey -alias mydomain -keyalg RSA -keystore keystore.jks -keysize mydomain ...

  3. [洛谷P3242] [HNOI2015]接水果

    洛谷题目链接:[HNOI2015]接水果 题目描述 风见幽香非常喜欢玩一个叫做 osu!的游戏,其中她最喜欢玩的模式就是接水果.由于她已经DT FC 了The big black, 她觉得这个游戏太简 ...

  4. jQuery简单的Ajax调用

    index.php 的代码如下: <!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"& ...

  5. 联系博主 Contact

    李莫 / Ray OI 蒟蒻一只 / A Player of Olympiad in Informatics QQ:740929894 邮箱 / Email :rayking2017@outlook. ...

  6. windows10安装oracle11g报错ORA-01034、ORA-01078

    ORA-01034表示数据库实例未建立,可以先用管理员账号进入一个空白实例 sqlplus / as sysdba; 如果您当前使用的账号是安装oracle的账号,则不需要账号密码就可以登陆oracl ...

  7. 25、如何实现redis集群?

    由于Redis出众的性能,其在众多的移动互联网企业中得到广泛的应用.Redis在3.0版本前只支持单实例模式,虽然现在的服务器内存可以到100GB.200GB的规模,但是单实例模式限制了Redis没法 ...

  8. ASP.NET AjaxControlToolkit-Framework4.0 配置实用(简单介绍CalendarExtender日期控件)

    1:下载:AjaxControlToolkit Ajax Control Toolkit .NET 4 Ajax Control Toolkit .NET 4.5 Ajax Control Toolk ...

  9. canvas_简单练习

    效果图 实现原理: 1.定义canvas标签. 2.获取canvas标签节点,创建canvas2D. 3.在canvas进行画图. 效果代码: <!DOCTYPE html> <ht ...

  10. 安全测试===sqlmap(零)转载

    本文转自:https://blog.werner.wiki/sqlmap-study-notes-0/ 感谢作者的整理,如有侵权,立删 零.前言 这篇文章是我学习Sqlmap的用法时做的笔记,记录了S ...