CF1099A.Snowball

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 u1u_1 and is located at height d1d_1, the second one — u2u_2 and d2d_2 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.

今天早晨异常大雪纷飞。Meshanya 决定出门,结果发现一个巨大的雪球正沿着山坡滚落!幸运的是,这座山坡上恰好有两块石头。

初始时,雪球位于高度 hh 处,重量为 ww。每一秒内,将按以下顺序发生一系列事件:雪球的重量增加 ii,其中 ii 为雪球当前所处的高度;接着雪球撞击该高度处的石头(若该高度存在石头);最后雪球向下移动一米。若雪球到达高度为 0 的位置,则停止运动。

山坡上恰好有两块石头:第一块石头重量为 u1u_1,位于高度 d1d_1;第二块石头重量为 u2u_2,位于高度 d2d_2。当雪球撞击其中任一石头时,其重量会减少该石头的重量。若撞击后雪球重量变为负数,则其重量重置为 0,但雪球仍继续按前述规则运动。

求雪球停止运动(即到达高度 0)时的重量。

输入格式

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

Second line contains two integers u1u_1 and d1d_1 — weight and height of the first stone (0≤u1≤1000 \le u_1 \le 100; 1≤d1≤h1 \le d_1 \le h).

Third line contains two integers u2u_2 and d2d_2 — weight and heigth of the second stone (0≤u2≤1000 \le u_2 \le 100; 1≤d2≤h1 \le d_2 \le h; d1≠d2d_1 \ne d_2). Notice that stones always have different heights.

第一行包含两个整数 ww 和 hh —— 雪球的初始重量和高度(0≤w≤1000 \le w \le 100;1≤h≤1001 \le h \le 100)。

第二行包含两个整数 u1u_1 和 d1d_1 —— 第一块石头的重量和高度(0≤u1≤1000 \le u_1 \le 100;1≤d1≤h1 \le d_1 \le h)。

第三行包含两个整数 u2u_2 和 d2d_2 —— 第二块石头的重量和高度(0≤u2≤1000 \le u_2 \le 100;1≤d2≤h1 \le d_2 \le h;d1≠d2d_1 \ne d_2)。注意:两块石头的高度总是不同。

输出格式

Output a single integer — final weight of the snowball after it reaches height 0.

输出一个整数——雪球到达高度 0 时的最终重量。

输入输出样例

  • 输入#1

    4 3
    1 1
    1 2

    输出#1

    8
  • 输入#2

    4 3
    9 2
    0 1

    输出#2

    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.

在第一个例子中,初始时一个重量为 4 的雪球位于高度 3 处,另有两块石头,重量均为 1,分别位于高度 1 和 2 处。接下来依次发生以下事件:

  • 雪球的重量增加 3(当前高度),变为 7。
  • 雪球向下移动 1 米,当前高度变为 2。
  • 雪球的重量增加 2(当前高度),变为 9。
  • 雪球撞击石头,其重量减少 1(石头的重量),变为 8。
  • 雪球向下移动 1 米,当前高度变为 1。
  • 雪球的重量增加 1(当前高度),变为 9。
  • 雪球撞击石头,其重量减少 1(石头的重量),变为 8。
  • 雪球向下移动 1 米,当前高度变为 0。

因此,最终雪球的重量为 8。

输入解题思路,AI测评打分。不知道怎么写?

首页