1195B.md (2948B)
1 Source: https://codeforces.com/problemset/problem/1195/B 2 3 B. Sport Mafia 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Each evening after the dinner the SIS's students gather together to play the game of Sport Mafia. 22 23 For the tournament, Alya puts candies into the box, which will serve as a prize for a winner. To do that, she performs $n$ 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: 24 25 * 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 $1$; 26 * the second option is to put candies in the box. In this case, Alya will put $1$ more candy, than she put in the previous time. 27 28 Thus, if the box is empty, then it can only use the second option. 29 30 For example, one possible sequence of Alya's actions look as follows: 31 32 * put one candy into the box; 33 * put two candies into the box; 34 * eat one candy from the box; 35 * eat one candy from the box; 36 * put three candies into the box; 37 * eat one candy from the box; 38 * put four candies into the box; 39 * eat one candy from the box; 40 * put five candies into the box; 41 42 This way she will perform $9$ actions, the number of candies at the end will be $11$, while Alya will eat $4$ candies in total. 43 44 You know the total number of actions $n$ and the number of candies at the end $k$. 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 $n$ and $k$ the answer always exists. 45 46 Please note, that during an action of the first option, Alya takes out and eats exactly one candy. 47 48 Input 49 50 The first line contains two integers $n$ and $k$ ($1 \le n \le 10^9$; $0 \le k \le 10^9$) — the total number of moves and the number of candies in the box at the end. 51 52 It's guaranteed, that for the given $n$ and $k$ the answer exists. 53 54 Output 55 56 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. 57 58 Examples 59 60 Input 61 62 ``` 63 1 1 64 ``` 65 66 Output 67 68 ``` 69 0 70 ``` 71 72 Input 73 74 ``` 75 9 11 76 ``` 77 78 Output 79 80 ``` 81 4 82 ``` 83 84 Input 85 86 ``` 87 5 0 88 ``` 89 90 Output 91 92 ``` 93 3 94 ``` 95 96 Input 97 98 ``` 99 3 2 100 ``` 101 102 Output 103 104 ``` 105 1 106 ``` 107 108 Note 109 110 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 $0$ candies. 111 112 In the second example the possible sequence of Alya's actions looks as follows: 113 114 * put $1$ candy, 115 * put $2$ candies, 116 * eat a candy, 117 * eat a candy, 118 * put $3$ candies, 119 * eat a candy, 120 * put $4$ candies, 121 * eat a candy, 122 * put $5$ candies. 123 124 This way, she will make exactly $n=9$ actions and in the end the box will contain $1+2-1-1+3-1+4-1+5=11$ candies. The answer is $4$, since she ate $4$ candies in total.