Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Christmas Tower - Problem Description Daiwik received an exciting Christmas present from his Secret Santa. The present consists of multiple repeated blocks, each varying in
Christmas Tower
Problem Description
Daiwik received an exciting Christmas present from his Secret Santa. The present consists of multiple repeated blocks, each varying in size. There are five unique blocks, all with identical width but varying heights. Daiwik's task is to construct a tower using these blocks, ensuring he uses the maximum number of blocks and the overall height does not surpass a specified height H
Given that Daiwik has an infinite supply of each block type, print the block heights prioritizing the frequencies in descending order, at which they were utilized in constructing the tower. If one or more type of blocks are used with same frequency, then print them in the ascending order of their heights.
Constraints
L
heights of five blocks
Input
First line consists of L denoting the height of the tower that Daiwik is going to build.
Next line consists of five space separated integers denoting the heights of the blocks that Daiwik have.
Output
Print the block heights in descending order based on their frequency of usage in constructing the tower, separated by space. If one or more type of blocks are used with same frequency, then print them in the ascending order of their heights. Print "Impossible" if its not possible to construct a tower of height H
Time Limit secs
Examples
Example :
Input
Output:
Explanation:
To construct a tower with a height of utilizing blocks of sizes Daiwik can opt for five blocks with a height and a single block with a height of This configuration would yield a total height of
Example
Input:
Output:
Impossible
Explanation:
Constructing a tower of height using the provided combination of blocks is not feasible. Hence, print "Impossible".
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started