Reference: https://www.hackerrank.com/challenges/lisa-workbook/problem
Lisa just got a new math workbook. A workbook contains exercise problems, grouped into chapters. Lisa believes a problem to be special if its index (within a chapter) is the same as the page number where it's located. The format of Lisa's book is as follows:
- There are
$n$ chapters in Lisa's workbook, numbered from$1$ to$n$ . - The
$i^{th}$ chapter has$arr[i]$ problems, numbered from$1$ to$arr[i]$ . - Each page can hold up to
$k$ problems. Only a chapter's last page of exercises may contain fewer than$k$ problems. - Each new chapter starts on a new page, so a page will never contain problems from more than one chapter.
- The page number indexing starts at
$1$ .
Given the details for Lisa's workbook, can you count its number of special problems?
For example, Lisa's workbook contains
Note: See the diagram in the Explanation section for more details.
The first line contains two integers
The second line contains
$1 \leq n,k,arr[i] \leq 100$
Print the number of special problems in Lisa's workbook.
5 3
4 2 6 1 10
4
The diagram below depicts Lisa's workbook with
There are
