Preparing for War
Time limit2sMemory limit256 MB
Given group sizes in strict order, place all soldiers in a rectangle X by Y so that adjacent different-group pairs are at most k, and find the maximum Y for each k from 0 to N-1.
- Level
Hard8 of 10
- Topics
- Math, Greedy, Number theory, Implementation
- Solved
- No attempts yet
Problem
The kingdom of Polymath is preparing for war to conquer its neighbor Scienceboard. You have been asked to design the battle formation for the war, and you are now studying formations.
Given the terrain of the war zone, the most efficient formation appears to be a rectangular one. That is, a rectangle with rows and columns filled by exactly soldiers. If the number of soldiers does not divide evenly and some are left over or missing, such a formation cannot be made.
Since the Polymath civilization has long subjugated many small neighboring countries with its strong military, its army contains soldiers from different ethnic groups. In particular, the number of soldiers from the -th ethnic group participating in this war is exactly .
Because rank depends on ethnic group, the positions of the soldiers cannot be assigned arbitrarily. In particular, when , a soldier from the -th ethnic group must always stand in front of a soldier from the -th ethnic group. Here, a soldier at row , column standing in front of a soldier at row , column means that one of the following two conditions holds.
- and
However, this arrangement has a slight problem: if soldiers from different ethnic groups are adjacent side by side, a fight will break out. Here, a soldier at row , column and a soldier at row , column being adjacent side by side means that and .
When you report this problem, the army officers of the kingdom decide to use peace stones to prevent fights. Using the power of a peace stone can prevent a fight even when soldiers from different ethnic groups are adjacent, but one stone can prevent only one fight. That is, if you have peace stones, fights will not break out only when the number of adjacent pairs of soldiers from different ethnic groups is at most .
The army officers believe that the wider the formation is, that is, the larger is, the stronger the army is. Therefore, you must find a formation satisfying the above conditions with the largest possible value of . However, information about the peace stones is a state secret, so you do not know exactly how many peace stones there are. Thus, you decide to find the maximum possible value of for every integer with .
Input
The first line gives the number of ethnic groups .
The next line gives the number of soldiers in each ethnic group, .
Output
On the first line, print the maximum possible value of for every integer with , separated by spaces.
Constraints
- (where )