Cut the Sequence
题号:NC51196
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 32 M,其他语言64 M
64bit IO Format: %lld

题目描述

Given an integer sequence of length N, you are to cut the sequence into several parts every one of which is a consecutive subsequence of the original sequence. Every part must satisfy that the sum of the integers in the part is not greater than a given integer M. You are to find a cutting that minimizes the sum of the maximum integer of each part.

输入描述:

The first line of input contains two integer N , M. The following line contains N integers describes the integer sequence. Every integer in the sequence is between 0 and 1 000 000 inclusively.

输出描述:

Output one integer which is the minimum sum of the maximum integer of each part. If no such cuttings exist, output −1.
示例1

输入

复制
8 17
2 2 2 8 1 8 2 1

输出

复制
12

备注:

Use 64-bit integer type to hold M.