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. XMind 8 破解补丁 XMindCrack.jar注册机激活教程

    XMind 8 破解补丁 XMindCrack.jar注册机激活教程 Xmind 8 update7破解版(附破解教程|激活补丁|序列号) 思维导图 XMind 8 Update 7 Pro 破解版 ...

  2. C#中static void Main(string[] args)的含义

    static:是将main方法声明为静态的. void:说明main方法不会返回任何内容. String[]args:这是用来接收命令行传入的参数,String[]是声明args是可以存储字符串数组. ...

  3. JSX 的基本语法规则

    JSX 的基本语法规则:遇到 HTML 标签(以 < 开头),就用 HTML 规则解析:遇到代码块(以 { 开头),就用 JavaScript 规则解析

  4. [洛谷P3527] [POI2011]MET-Meteors

    洛谷题目链接:[POI2011]MET-Meteors 题意翻译 Byteotian Interstellar Union有N个成员国.现在它发现了一颗新的星球,这颗星球的轨道被分为M份(第M份和第1 ...

  5. PowerDesigner16 用例图

    用例图主要用来描述角色以及角色与用例之间的连接关系.说明的是谁要使用系统,以及他们使用该系统可以做些什么.一个用例图包含了多个模型元素,如系统.参与者和用例,并且显示这些元素之间的各种关系,如泛化.关 ...

  6. 归并排序Merge sort2

    原理,把原始数组分成若干子数组,对每一个子数组进行排序, 继续把子数组与子数组合并,合并后仍然有序,直到全部合并完,形成有序的数组 举例 无序数组[6 2 4 1 5 9] 先看一下每个步骤下的状态, ...

  7. photoshop的魔棒工具怎么用来抠图

    魔棒工具是photoshop中提供的一种可以快速形成选区的工具,对于颜色边界分界明显的图片,能够一键形成选区,方便快捷. 本教程通过一个简单的实例,教新手怎么用Photoshop魔棒工具快速形成抠图选 ...

  8. Android项目分包---总结-------直接使用

    注: 本文是从该文摘抄而来的.简单的说,就是阅读了该文,然后,再自己复述,复制形成该文.   1.罗列Android项目的分包规则   微盘使用分包规则   如下:     1).第一层com.sin ...

  9. bzoj 3126: [Usaco2013 Open]Photo——单调队列优化dp

    Description 给你一个n长度的数轴和m个区间,每个区间里有且仅有一个点,问能有多少个点 Input * Line 1: Two integers N and M. * Lines 2..M+ ...

  10. 【51NOD】1096 距离之和最小

    [算法]数学 [题解] 其实就是求中位数,奇数个点就是最中间的点,偶数个点就是最中间两个点和它们之间的区域皆可(所以偶数不必取到两点正中央,取两点任意一点即可). 我们可以想象现在x轴上有n个点,我们 ...