Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You have m wood chips of varying lengths, and you want to stack them all in a cone to light a fire. The maximum difference

image text in transcribedimage text in transcribed You have m wood chips of varying lengths, and you want to stack them all in a cone to light a fire. The maximum difference between the lengths of the wood chips on either side (A) tells you how stable the stack is. The smaller the value of A, the more stable the stack. For a perfect campfire, you want to stack all the wood chips as stably as possible. Write a program that prints out the value of A. Example: Given 5 pieces of firewood, stack them as shown below. Given a piece of wood with length l2, the pieces on either side of it are pieces of wood with lengths l3 and l1. L5 -> L3 -> L2 -> L1 -> L4 -> L5 Condition All wood chips have different lengths. The lengths of the chunks come in unordered. Input Format On the first line, the number of firewood, m, is given. (3m100000,m is an integer) On the second line, the lengths li of all the firewoods are given, separated by spaces. (1li100000, li is an integer) Output Format Print the value of A on the first line. Input 7 1521071241 Output 6 Write in Python, and use a Greedy algorithm. Timeout per a testcase =0.87s. therefore measuring time is necessary. Include it in the code. Important) I would be very grateful if you could attach a screenshot of the sample output when you put in the sample input

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals Design And Implementation

Authors: David M. Kroenke

5th Edition

B000CSIH5A, 978-0023668814

More Books

Students also viewed these Databases questions