Question: Problem 2- Container shuffle A freight company has a number of shipping containers arriving and barges leaving at various moments throughout the day. Each container

 Problem 2- Container shuffle A freight company has a number of
shipping containers arriving and barges leaving at various moments throughout the day.
Each container has an associated value and is stored in their warehouse

Problem 2- Container shuffle A freight company has a number of shipping containers arriving and barges leaving at various moments throughout the day. Each container has an associated value and is stored in their warehouse on arrival. When a ship arrives, the company's policy is to always pack the most valuable containers from the warehouse onto the ship. If a ship's capacity is more than the number of containers that are in the warehouse, then all of the containers are packed onto the ship, and the ship leaves with whatever has been loaded on it. The space in the warehouse is unlimited. Determine the total value that has been loaded onto each ship as it departs. Input Format The first line contains a single integer Each of the next lines contains a single letter and an integer. It will be one of two possible formats: a vto denote the arrival of a container with a value of s c to denote the arrival of a ship whose capacity is Constraints Output Format Each time that a ship arrives, print, on a separate line, the total value of the containers that would have been loaded onto it. Sample Input 0 13 a 100 a 70 a 150 a 30 a 50 a 200 s 3 a 10 a 20 s 4

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!