codeforces-scrape

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

1491C.md (2416B)


      1 Source: https://codeforces.com/problemset/problem/1491/C
      2 
      3 C. Pekora and Trampoline
      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 There is a trampoline park with $n$ trampolines in a line. The $i$-th of which has strength $S_i$.
     22 
     23 Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice.
     24 
     25 If at the moment Pekora jumps on trampoline $i$, the trampoline will launch her to position $i + S_i$, and $S_i$ will become equal to $\max(S_i-1,1)$. In other words, $S_i$ will decrease by $1$, except of the case $S_i=1$, when $S_i$ will remain equal to $1$.
     26 
     27 If there is no trampoline in position $i + S_i$, then this pass is over. Otherwise, Pekora will continue the pass by jumping from the trampoline at position $i + S_i$ by the same rule as above.
     28 
     29 Pekora can't stop jumping during the pass until she lands at the position larger than $n$ (in which there is no trampoline). Poor Pekora!
     30 
     31 Pekora is a naughty rabbit and wants to ruin the trampoline park by reducing all $S_i$ to $1$. What is the minimum number of passes she needs to reduce all $S_i$ to $1$?
     32 
     33 Input
     34 
     35 The first line contains a single integer $t$ ($1 \le t \le 500$) — the number of test cases.
     36 
     37 The first line of each test case contains a single integer $n$ ($1 \leq n \leq 5000$) — the number of trampolines.
     38 
     39 The second line of each test case contains $n$ integers $S_1, S_2, \dots, S_n$ ($1 \le S_i \le 10^9$), where $S_i$ is the strength of the $i$-th trampoline.
     40 
     41 It's guaranteed that the sum of $n$ over all test cases doesn't exceed $5000$.
     42 
     43 Output
     44 
     45 For each test case, output a single integer — the minimum number of passes Pekora needs to do to reduce all $S_i$ to $1$.
     46 
     47 Example
     48 
     49 Input
     50 
     51 ```
     52 3
     53 7
     54 1 4 2 2 2 2 2
     55 2
     56 2 3
     57 5
     58 1 1 1 1 1
     59 ```
     60 
     61 Output
     62 
     63 ```
     64 4
     65 3
     66 0
     67 ```
     68 
     69 Note
     70 
     71 For the first test case, here is an optimal series of passes Pekora can take. (The bolded numbers are the positions that Pekora jumps into during these passes.)
     72 
     73 * $[1,4,\textbf{2},2,\textbf{2},2,\textbf{2}]$
     74 * $[1,\textbf{4},1,2,1,\textbf{2},1]$
     75 * $[1,\textbf{3},1,2,\textbf{1},\textbf{1},\textbf{1}]$
     76 * $[1,\textbf{2},1,\textbf{2},1,\textbf{1},\textbf{1}]$
     77 
     78 For the second test case, the optimal series of passes is show below.
     79 
     80 * $[\textbf{2},3]$
     81 * $[1,\textbf{3}]$
     82 * $[1,\textbf{2}]$
     83 
     84 For the third test case, all $S_i$ are already equal to $1$.