codeforces-scrape

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

1190A.md (3225B)


      1 Source: https://codeforces.com/problemset/problem/1190/A
      2 
      3 A. Tokitsukaze and Discard Items
      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 Recently, Tokitsukaze found an interesting game. Tokitsukaze had $n$ items at the beginning of this game. However, she thought there were too many items, so now she wants to discard $m$ ($1 \le m \le n$) special items of them.
     22 
     23 These $n$ items are marked with indices from $1$ to $n$. In the beginning, the item with index $i$ is placed on the $i$-th position. Items are divided into several pages orderly, such that each page contains exactly $k$ positions and the last positions on the last page may be left empty.
     24 
     25 Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded.
     26 
     27  ![](https://espresso.codeforces.com/b0630de2a7894beb259b030394db5c53e1ad83d3.png) Consider the first example from the statement: $n=10$, $m=4$, $k=5$, $p=[3, 5, 7, 10]$. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices $3$ and $5$. After, the first page remains to be special. It contains $[1, 2, 4, 6, 7]$, Tokitsukaze discards the special item with index $7$. After, the second page is special (since it is the first page containing a special item). It contains $[9, 10]$, Tokitsukaze discards the special item with index $10$. 
     28 
     29 Tokitsukaze wants to know the number of operations she would do in total.
     30 
     31 Input
     32 
     33 The first line contains three integers $n$, $m$ and $k$ ($1 \le n \le 10^{18}$, $1 \le m \le 10^5$, $1 \le m, k \le n$) — the number of items, the number of special items to be discarded and the number of positions in each page.
     34 
     35 The second line contains $m$ distinct integers $p_1, p_2, \ldots, p_m$ ($1 \le p_1 \lt p_2 \lt \ldots \lt p_m \le n$) — the indices of special items which should be discarded.
     36 
     37 Output
     38 
     39 Print a single integer — the number of operations that Tokitsukaze would do in total.
     40 
     41 Examples
     42 
     43 Input
     44 
     45 ```
     46 10 4 5
     47 3 5 7 10
     48 ```
     49 
     50 Output
     51 
     52 ```
     53 3
     54 ```
     55 
     56 Input
     57 
     58 ```
     59 13 4 5
     60 7 8 9 10
     61 ```
     62 
     63 Output
     64 
     65 ```
     66 1
     67 ```
     68 
     69 Note
     70 
     71 For the first example:
     72 
     73 * In the first operation, Tokitsukaze would focus on the first page $[1, 2, 3, 4, 5]$ and discard items with indices $3$ and $5$;
     74 * In the second operation, Tokitsukaze would focus on the first page $[1, 2, 4, 6, 7]$ and discard item with index $7$;
     75 * In the third operation, Tokitsukaze would focus on the second page $[9, 10]$ and discard item with index $10$.
     76 
     77 For the second example, Tokitsukaze would focus on the second page $[6, 7, 8, 9, 10]$ and discard all special items at once.