PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000254. Chia mảng để tối thiểu hóa tổng đoạn lớn nhất (Split Array Largest Sum)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Chia mảng để tối thiểu hóa tổng đoạn lớn nhất (Split Array Largest Sum)
Split Array Largest Sum
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Given nonnegative integers , choose cuts between elements to obtain exactly nonempty contiguous blocks. Minimize the largest block sum. Output the optimal value, not the cuts.
Input
The first line contains : the number of elements and blocks.
The second line contains exactly integers , representing the array elements.
Output
Print the smallest possible largest block sum.
Subtasks
- Subtask 1 (20 points): ; for every ; .
- Subtask 2 (30 points): ; for every ; ; .
- Subtask 3 (50 points): ; for every ; .
Examples
Input
5 2
7 2 5 10 8
Output
18
Explanation
The four possible cuts give sum pairs , , and . Their maxima are 25, 23, 18 and 24. Cutting after the third element achieves 18.