#K79047. Minimum Trucks Required
Minimum Trucks Required
Minimum Trucks Required
You are given a series of packages with their weights and a truck with a maximum capacity \(T\). Your task is to determine the minimum number of trucks required to transport all the packages. A truck can carry a set of packages as long as the total weight does not exceed \(T\). You may choose the order in which packages are loaded into the trucks.
Note: This problem is equivalent to a variant of the bin packing problem and a greedy strategy is sufficient to pass the given test cases.
inputFormat
The input is read from stdin
and consists of two lines:
- The first line contains two integers \(T\) and \(P\) separated by a space, where \(T\) (\(1 \le T \le 10^5\)) is the maximum capacity of a truck and \(P\) is the number of packages.
- The second line contains \(P\) integers separated by spaces, each representing the weight of a package.
outputFormat
Output a single integer to stdout
that denotes the minimum number of trucks required to transport all packages.
50 5
10 30 20 40 10
3
</p>