1612C.md (3036B)
1 Source: https://codeforces.com/problemset/problem/1612/C 2 3 C. Chat Ban 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 512 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 You are a usual chat user on the most famous streaming platform. Of course, there are some moments when you just want to chill and spam something. 22 23 More precisely, you want to spam the emote triangle of size $k$. It consists of $2k-1$ messages. The first message consists of one emote, the second one — of two emotes, ..., the $k$-th one — of $k$ emotes, the $k+1$-th one — of $k-1$ emotes, ..., and the last one — of one emote. 24 25 For example, the emote triangle for $k=3$ consists of $5$ messages: 26 27  28 29 Of course, most of the channels have auto moderation. Auto moderator of the current chat will ban you right after you spam at least $x$ emotes in succession (you can assume you are the only user in the chat). Now you are interested — how many messages will you write before getting banned? Or maybe you will not get banned at all (i.e. will write all $2k-1$ messages and complete your emote triangle successfully)? Note that if you get banned as a result of writing a message, this message is also counted. 30 31 You have to answer $t$ independent test cases. 32 33 Input 34 35 The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. The next $t$ lines describe test cases. 36 37 The only line of the test case contains integers $k$ and $x$ ($1 \le k \le 10^9; 1 \le x \le 10^{18}$). 38 39 Output 40 41 For each test case, print the number of messages you will write before getting banned for the corresponding values $k$ and $x$. 42 43 Example 44 45 Input 46 47 ``` 48 7 49 4 6 50 4 7 51 1 2 52 3 7 53 2 5 54 100 1 55 1000000000 923456789987654321 56 ``` 57 58 Output 59 60 ``` 61 3 62 4 63 1 64 4 65 3 66 1 67 1608737403 68 ``` 69 70 Note 71 72 Let's analyze the test cases of the example. 73 74 1. In the first test case, you write three messages containing $1$, $2$ and $3$ emotes respectively, and since $1 + 2 + 3 \ge 6$, you get banned after that. 75 2. In the second test case, you write four messages containing $1$, $2$, $3$ and $4$ emotes respectively, and since $1 + 2 + 3 + 4 \ge 7$, you get banned after that. 76 3. In the third test case, you write one message containing exactly $1$ emote. It doesn't get you banned, since $1 \lt 2$, but you have already finished posting your emote triangle. So you wrote one message successfully. 77 4. In the fourth test case, you write four messages containing $1$, $2$, $3$ and $2$ emotes respectively, and since $1 + 2 + 3 + 2 \ge 7$, you get banned after that. 78 5. In the fifth test case, you write three messages containing $1$, $2$ and $1$ emote respectively. It doesn't get you banned, since $1 + 2 + 1 \lt 5$, but you have already finished posting your emote triangle. So you wrote three messages successfully. 79 6. In the sixth test case, since $x = 1$, you get banned as soon as you send your first message. 80 7. The seventh test case is too large to analyze, so we'll skip it.