Waging War Peacefully
Time limit5sMemory limit256 MB
Given group sizes A1..AN, find the largest rectangle width Y that fits all soldiers in row-major order with at most k row-boundary conflicts, for every k from 0 to N-1.
- Level
Hard9 of 10
- Topics
- Math, Number theory, Prefix sum, Greedy
- Solved
- No attempts yet
Problem
The Polymath civilization is known to have fought a large-scale war called the First Donga War around 8500 BC to subjugate its neighbor Scienceboard. You are studying the army tactics of the Polymath civilization at that time. Fortunately, you obtained some useful information from old documents.
According to their book of tactics, the army of the Polymath civilization was formed into a precise rectangular formation. That is, a rectangle with rows and columns is filled by exactly soldiers. Cases where the number of soldiers did not divide exactly, leaving some soldiers left over or short, were not allowed.
Since the Polymath civilization had originally subjugated many small neighboring countries with its strong military power, its army also contained different ethnic groups. In particular, records show that among the soldiers who took part in the First Donga War, exactly soldiers were from the -th ethnic group.
The Polymath civilization discriminated against its citizens based on ethnic origin, and the army was affected by this as well. In particular, when , a soldier from the -th ethnic group always had to 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 had a slight problem: whenever soldiers from different ethnic groups were adjacent side by side, a fight always broke out. Here, a soldier at row , column and a soldier at row , column being adjacent side by side means that and .
The army officers of the Polymath civilization used peace stones to prevent fights. Using the power of a peace stone prevents 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, then the number of pairs of adjacent soldiers from different ethnic groups must be at most for no fight to occur.
Through various records, you discovered that the officers of the Polymath civilization believed that the wider the formation was, that is, the larger was, the stronger the army was. Therefore, you conjecture that the formation used in the First Donga War was also a perfectly rectangular formation with the largest value among formations where no fight occurs. However, since you have not yet determined exactly how many peace stones the Polymath civilization had, you decided 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, output the maximum possible value of for each with , separated by spaces.
Constraints
- (where )