{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eGiven an integer sequence { \u003ci\u003ea\u003csub\u003en\u003c/sub\u003e\u003c/i\u003e } of length \u003ci\u003eN\u003c/i\u003e, 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 \u003ci\u003eM\u003c/i\u003e. You are to find a cutting that minimizes the sum of the maximum integer of each part.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cspan lang\u003d\"en-us\"\u003e\u003cp\u003eThe first line of input contains two integer \u003ci\u003eN\u003c/i\u003e (0 \u0026lt; \u003ci\u003eN\u003c/i\u003e ≤ 100 000), \u003ci\u003eM\u003c/i\u003e. The following line contains \u003ci\u003eN\u003c/i\u003e integers describes the integer sequence. Every integer in the sequence is between 0 and 1 000 000 inclusively.\u003c/p\u003e\u003c/span\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eOutput one integer which is the minimum sum of the maximum integer of each part. If no such cuttings exist, output −1.\u003c/p\u003e"}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e8 17\r\n2 2 2 8 1 8 2 1\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e12\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Hint","value":{"format":"HTML","content":"\u003cp\u003eUse 64-bit integer type to hold \u003ci\u003eM\u003c/i\u003e.\u003c/p\u003e"}}]}