CF1195B.Sport Mafia

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Each evening after the dinner the SIS's students gather together to play the game of Sport Mafia.

For the tournament, Alya puts candies into the box, which will serve as a prize for a winner. To do that, she performs nn actions. The first action performed is to put a single candy into the box. For each of the remaining moves she can choose from two options:

  • the first option, in case the box contains at least one candy, is to take exactly one candy out and eat it. This way the number of candies in the box decreased by 11;
  • the second option is to put candies in the box. In this case, Alya will put 11 more candy, than she put in the previous time.

Thus, if the box is empty, then it can only use the second option.

For example, one possible sequence of Alya's actions look as follows:

  • put one candy into the box;
  • put two candies into the box;
  • eat one candy from the box;
  • eat one candy from the box;
  • put three candies into the box;
  • eat one candy from the box;
  • put four candies into the box;
  • eat one candy from the box;
  • put five candies into the box;

This way she will perform 99 actions, the number of candies at the end will be 1111, while Alya will eat 44 candies in total.

You know the total number of actions nn and the number of candies at the end kk. You need to find the total number of sweets Alya ate. That is the number of moves of the first option. It's guaranteed, that for the given nn and kk the answer always exists.

Please note, that during an action of the first option, Alya takes out and eats exactly one candy.

每天晚饭后,SIS 的学生们都会聚在一起玩“体育黑手党”游戏。

为了举办锦标赛,Alya 会往一个盒子里放入糖果,作为获胜者的奖品。为此,她执行 nn 次操作。第一次操作是往盒子里放入一颗糖果。对于其余每次操作,她可以从以下两种选项中选择一种:

  • 第一个选项:当盒子里至少有一颗糖果时,从中恰好取出一颗糖果并吃掉。这样,盒中的糖果数量减少 11;
  • 第二个选项:往盒子里放入糖果。此时,Alya 放入的糖果数量比上一次放入的数量多 11 颗。

因此,若盒子为空,则她只能选择第二个选项。

例如,Alya 的一种可能的操作序列如下:

  • 往盒子里放入一颗糖果;
  • 往盒子里放入两颗糖果;
  • 从盒子里取出并吃掉一颗糖果;
  • 从盒子里取出并吃掉一颗糖果;
  • 往盒子里放入三颗糖果;
  • 从盒子里取出并吃掉一颗糖果;
  • 往盒子里放入四颗糖果;
  • 从盒子里取出并吃掉一颗糖果;
  • 往盒子里放入五颗糖果;

这样,她共执行了 99 次操作,最终盒中糖果数为 1111,而 Alya 总共吃掉了 44 颗糖果。

已知总操作次数 nn 和最终盒中糖果数量 kk,你需要求出 Alya 吃掉的糖果总数,即第一种操作(取糖果并吃掉)的执行次数。题目保证,对给定的 nn 和 kk,答案一定存在。

请注意:在执行第一种操作时,Alya 每次恰好取出并吃掉一颗糖果。

输入格式

The first line contains two integers nn and kk (1≤n≤1091 \le n \le 10^9; 0≤k≤1090 \le k \le 10^9) — the total number of moves and the number of candies in the box at the end.

It's guaranteed, that for the given nn and kk the answer exists.

第一行包含两个整数 nn 和 kk(1≤n≤1091 \le n \le 10^9;0≤k≤1090 \le k \le 10^9)—— 分别表示总移动次数和最终盒子中的糖果数量。

保证对于给定的 nn 和 kk,答案存在。

输出格式

Print a single integer — the number of candies, which Alya ate. Please note, that in this problem there aren't multiple possible answers — the answer is unique for any input data.

输出一个整数——Alya 吃掉的糖果数量。请注意,本题不存在多个可能的答案——对于任意输入数据,答案都是唯一的。

输入输出样例

  • 输入#1

    1 1

    输出#1

    0
  • 输入#2

    9 11

    输出#2

    4
  • 输入#3

    5 0

    输出#3

    3
  • 输入#4

    3 2

    输出#4

    1

说明/提示

In the first example, Alya has made one move only. According to the statement, the first move is always putting one candy in the box. Hence Alya ate 00 candies.

In the second example the possible sequence of Alya's actions looks as follows:

  • put 11 candy,
  • put 22 candies,
  • eat a candy,
  • eat a candy,
  • put 33 candies,
  • eat a candy,
  • put 44 candies,
  • eat a candy,
  • put 55 candies.

This way, she will make exactly n=9n=9 actions and in the end the box will contain 1+2−1−1+3−1+4−1+5=111+2-1-1+3-1+4-1+5=11 candies. The answer is 44, since she ate 44 candies in total.

在第一个例子中,Alya 仅执行了一次操作。根据题意,第一次操作总是向盒中放入一颗糖果。因此 Alya 吃掉了 00 颗糖果。

在第二个例子中,Alya 可能的操作序列如下所示:

  • 放入 11 颗糖果,
  • 放入 22 颗糖果,
  • 吃掉 11 颗糖果,
  • 吃掉 11 颗糖果,
  • 放入 33 颗糖果,
  • 吃掉 11 颗糖果,
  • 放入 44 颗糖果,
  • 吃掉 11 颗糖果,
  • 放入 55 颗糖果。

这样,她总共执行了恰好 n=9n=9 次操作,最终盒中糖果数量为 1+2−1−1+3−1+4−1+5=111+2-1-1+3-1+4-1+5=11 颗。答案为 44,因为她总共吃掉了 44 颗糖果。

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

首页