#K90892. Optimal Watertight Doors Placement
Optimal Watertight Doors Placement
Optimal Watertight Doors Placement
The safety of a ship is paramount, and one way to ensure it is by creating watertight compartments. In this problem, you are given the total length of the ship and the lengths of its compartments. Your task is to determine the optimal positions at which to install watertight doors such that the ship is divided into sections of equal design. More formally, if the ship has K compartments with given lengths, you need to output the cumulative lengths at which doors should be installed, i.e. the prefix sums of the compartments excluding the final compartment.
Note: Although the total length L is provided, it is simply the sum of the compartment lengths. The door positions should be printed as a series of numbers corresponding to the cumulative length after each compartment, not including the end of the last compartment.
Example: If the ship is divided into 4 compartments of lengths [25, 25, 25, 25], then the doors should be installed at positions 25, 50, and 75.
inputFormat
The first line of input contains two space-separated integers: L (the total length of the ship) and K (the number of compartments). The second line contains K space-separated integers representing the lengths of each compartment in order.
outputFormat
Output a single line containing K - 1 integers, which are the positions to place the watertight doors. These positions are the cumulative sums of the compartment lengths (excluding the final total, as the last door is not required).
## sample100 4
25 25 25 25
25 50 75