PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000234. Vận chuyển hàng trong D ngày (Capacity To Ship Packages Within D Days)
HỌC THEO LỘ TRÌNH
2 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Vận chuyển hàng trong D ngày (Capacity To Ship Packages Within D Days)
Capacity To Ship Packages Within D Days
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
A conveyor belt contains packages in a fixed order, with weights . Ship all packages in at most days using a ship of constant daily capacity .
Each day's cargo must consist of a consecutive prefix of the packages still waiting; its total weight must not exceed . Packages cannot be reordered or split.
Find the minimum integer capacity to finish on time.
Input
- The first line contains .
- The next line contains the positive package weights in conveyor order.
Output
Print the smallest possible ship capacity.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input
5 4
1 2 3 1 1
Output
3
Explanation
With capacity , ship , then , then , using only three of the four available days. Capacity cannot carry the package of weight , so the minimum is .