Rahul and his friends are making LEGO towers out of their LEGO bricks. His friends arrive at different times and join the existing group in LEGO tower building activity. The rules that Rahul and friends are following are as follows:
To maintain the balance of the tower, they decide to impose a maximum limit on the height of the tower
Each friend brings whatever number of bricks he has, but less than or equal to the maximum height allowed for the tower
In order to differentiate between bricks belonging to different friend, they decide to insert a plate between bricks brought by two friends
Height of each brick as well as height of each plate is 1 unit
Actual height of the constructed tower is total number of (bricks + plates) in that tower
Plate can only be added if bricks above belong to a different friend
In order to avoid losing bricks, they also agree that all the bricks belonging to one friend will be used only in construction of one tower
Once the construction of a new tower has begun, no brick/plate can be added to the previous tower
Help Rahul and friends such that they are of maximum height and minimum number of towers possible
You also have to minimize height factor while maintaining minimum number of towers.
Height factor = ∑ ((Maximum height allowed - height of tower)2)
Example:
Maximum height allowed: 10
Bricks contributed by friends: 6 3 5 2 4
Here we can make 3 towers such that
· 1st tower has 6 + 1 + 3 bricks, total of 10 (1 is for the height of LEGO plate)
· 2nd tower has 5 + 1 + 2 bricks, total of 8 (1 is for the height of LEGO plate)
· 3rd tower has 4 bricks
In this case height factor is: (10 - 10)2 + (10 - 8)2 + (10 - 4)2 = 40
Another way is
· 1st tower has 6 bricks
· 2nd tower has 3 + 1 + 5 bricks, total of 09 (1 is for the height of LEGO plate)
· 3rd tower has 2 + 1 + 4 bricks, total of 07 (1 is for the height of LEGO plate)
In this case, height factor is: (10 - 6)2 + (10 - 9)2 + (10 - 7)2 = 26
It is clear that height factor is minimum in the second case, so the output will be: (6) (3-5) (2-4)
Note: There are no test cases with more than one occurrence of minimum height factor.
Constraints
10 <= H <= 100
1 <= bricks brought by friends <= H
1 <= number of friends <= 10000
Answers
Answered by
0
Answer:
hi plz give me brain list
Attachments:
Similar questions