codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1455B.md (1993B)


      1 Source: https://codeforces.com/problemset/problem/1455/B
      2 
      3 B. Jumps
      4 
      5 time limit per test
      6 
      7 1 second
      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 You are standing on the $\mathit{OX}$-axis at point $0$ and you want to move to an integer point $x \gt 0$.
     22 
     23 You can make several jumps. Suppose you're currently at point $y$ ($y$ may be negative) and jump for the $k$-th time. You can:
     24 
     25 * either jump to the point $y + k$
     26 * or jump to the point $y - 1$.
     27 
     28 What is the minimum number of jumps you need to reach the point $x$?
     29 
     30 Input
     31 
     32 The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
     33 
     34 The first and only line of each test case contains the single integer $x$ ($1 \le x \le 10^6$) — the destination point.
     35 
     36 Output
     37 
     38 For each test case, print the single integer — the minimum number of jumps to reach $x$. It can be proved that we can reach any integer point $x$.
     39 
     40 Example
     41 
     42 Input
     43 
     44 ```
     45 5
     46 1
     47 2
     48 3
     49 4
     50 5
     51 ```
     52 
     53 Output
     54 
     55 ```
     56 1
     57 3
     58 2
     59 3
     60 4
     61 ```
     62 
     63 Note
     64 
     65 In the first test case $x = 1$, so you need only one jump: the $1$-st jump from $0$ to $0 + 1 = 1$.
     66 
     67 In the second test case $x = 2$. You need at least three jumps:
     68 
     69 * the $1$-st jump from $0$ to $0 + 1 = 1$;
     70 * the $2$-nd jump from $1$ to $1 + 2 = 3$;
     71 * the $3$-rd jump from $3$ to $3 - 1 = 2$;
     72 
     73 Two jumps are not enough because these are the only possible variants:
     74 
     75 * the $1$-st jump as $-1$ and the $2$-nd one as $-1$ — you'll reach $0 -1 -1 =-2$;
     76 * the $1$-st jump as $-1$ and the $2$-nd one as $+2$ — you'll reach $0 -1 +2 = 1$;
     77 * the $1$-st jump as $+1$ and the $2$-nd one as $-1$ — you'll reach $0 +1 -1 = 0$;
     78 * the $1$-st jump as $+1$ and the $2$-nd one as $+2$ — you'll reach $0 +1 +2 = 3$;
     79 
     80 In the third test case, you need two jumps: the $1$-st one as $+1$ and the $2$-nd one as $+2$, so $0 + 1 + 2 = 3$.
     81 
     82 In the fourth test case, you need three jumps: the $1$-st one as $-1$, the $2$-nd one as $+2$ and the $3$-rd one as $+3$, so $0 - 1 + 2 + 3 = 4$.