Ronit had always wished to become a writer. He became a very popular writer. However he knew that with popularity comes lots of work. Time passed and Ronit was deprived of sleep. His parents were now concerned. They advised him to minimize the amount of time he works each day. However Ronit was to complete N books in M days. He has to write the books in the given prescribed order but he can write any number of books each day. He can complete all the books before M days. He knew that he would take an amount of time q[i] to write his i_{th} book. He wanted to find out the minimum amount of time T such that if he worked for a time less than or equal to T each day, he could complete his work in or before M days, i.e. he wanted to find T such that t[i] <= T for i=1 to N, where t[i] is the amount of time spent on the i_{th} day. He is a very good writer but is weak in algorithms. So he wants you to help him out.

**Note**: Ronit cannot start working on a book on one day and complete it on the next day.

**Input:**

The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. The first line of each test case consists of two space separated integers, N and M, denoting number of books and number of days respectively. The second line of each test case consists of N space separated integers, the i_{th} integer denoting the time taken to write the i_{th} book.

**Output:**

Corresponding to each test case, print the desired output in a new line.

**Constraints:**

1<=T<=100

1<=N<=1000

1<=M<=N

1<=q[i]<=100

**Example:**

**Input:**

```
3
5 2
1 3 2 1 2
4 3
1 3 4 2
5 4
4 5 3 1 2
```

**Output:**

```
5
4
5
```

**Explanation:**

In the first test case, Ronit has 2 days to complete 5 books. He completes the first 2 books on the first day and takes a total time of 4<=5. He completes the remaining books on the second day and takes a total time of 5<=5. Hence T=5.

The remaining test cases follow from the same logic.

Author: akundusaltlake

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

PM_Pranay | 38 |

m_raju | 22 |

Piyush_43 | 22 |

abducodes | 22 |

RamduttSharma | 18 |

Pulkit__Sharma__ | 626 |

Anirban166 | 503 |

abducodes | 468 |

Found_me | 430 |

Yo_Nehru | 404 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4559 |

Login to report an issue on this page.