#K15656. Minimum Days to Finish Book

    ID: 24405 Type: Default 1000ms 256MiB

Minimum Days to Finish Book

Minimum Days to Finish Book

You are given a book which is divided into n chapters. The i-th chapter consists of a certain number of pages. A reader can only read at most K pages per day. Your task is to determine the minimum number of days required to read the entire book.

Formally, let \( chapters[i] \) denote the number of pages in the \( i\text{-th} \) chapter and let \( K \) denote the maximum pages that can be read in one day. The reader reads chapters sequentially. If reading the next chapter would cause the total number of pages read in the current day to exceed \( K \), then the reader starts a new day.

For example, given 4 chapters with page counts [10, 20, 30, 40] and \( K = 50 \), the optimal strategy is to read chapters as follows:

  • Day 1: Read chapters 1 and 2 (10+20=30 pages)
  • Day 2: Read chapter 3 (30 pages)
  • Day 3: Read chapter 4 (40 pages)
Thus, the answer is 3 days.

inputFormat

The input is read from standard input (stdin) and has the following format:

T
N1 K1
pages1[1] pages1[2] ... pages1[N1]
N2 K2
pages2[1] pages2[2] ... pages2[N2]
...
NT KT
pagesT[1] pagesT[2] ... pagesT[NT]

Where:

  • T is the number of test cases.
  • For each test case, the first line contains two integers: N (the number of chapters) and K (the maximum number of pages that can be read per day).
  • The following line contains N integers representing the number of pages in each chapter in order.

outputFormat

For each test case, output a single integer on a new line representing the minimum number of days required to finish reading the book.

The output should be written to standard output (stdout).

## sample
3
4 50
10 20 30 40
5 100
50 30 20 40 10
3 70
60 10 10
3

2 2

</p>