Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. Jamie's Water Can Jamie has to carry some amount of water to a particular location. There are n cans of water, but not all

image text in transcribed

image text in transcribed

2. Jamie's Water Can Jamie has to carry some amount of water to a particular location. There are n cans of water, but not all of them are completely filled with water. These cans may be consolidated. Determine the minimum number of cans needed to contain the required amount of water. Example n = 5 total = (3, 5, 3, 5, 5) used = 13, 2, 1, 3, 1] There are 5 cans of water. The total array represents the capacity of each can. The used array represents the amount of water already in each can. The first can is full, but the second can has 3 units of space remaining. Pour the entirety of the first can into the second and the second will be full. Each of the last three cans has room for more water, but the most efficient solution is to pour the contents of cans 3 and 5 into can 4. Now there are two 5 unit cans that are full and there are no other cans with water remaining in them. In this case, the minimum number of cans needed is 2. Function Description Complete the function minCans in the editor below. minCans has the following parameters: int used[n]: an array of integers where used[ denotes the amount of water in the ith can. int total[n]: an array of integers where total[u denotes the capacity of water of the ith can. Returns: int: an integer that denotes the minimum number of cans needed Constraints 1sns 1000 1 8 used[i] = 1000 1s totalls 1000

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

Statistical And Scientific Database Management International Working Conference Ssdbm Rome Italy June 21 23 1988 Proceedings Lncs 339

Authors: Maurizio Rafanelli ,John C. Klensin ,Per Svensson

1st Edition

354050575X, 978-3540505754

Students also viewed these Databases questions