Basic heap operations

Assignment Help Data Structure & Algorithms
Reference no: EM131116560

Heap
This question is designed to help you get a better understanding of basic heap operations. You will be given queries of 3 types:
• "1 v" -Add an element v to the heap.
• "2 v" -Delete the element v from the heap.
• "3" -Print the minimum of all the elements of the heap.
NOTE: It is guaranteed that the element to be deleted will be there in the heap. Also, at any instant, only distinct elements will be in the heap.

Input Format
The first line contains the number of queries, Q.
Each of the next Q lines contains a single query of any one of the 3 above mentioned types.

Constraints
1 ≤ Q ≤ 10^5
-10^9 ≤ v ≤ 10^9

Output Format
For each query of type 3, print the minimum value on a single line.

Sample Input
5
1 4
1 9
3
2 4
3

Sample Output
4
9

Explanation
After the first 2 queries, the heap contains {4,9}. Printing the minimum gives 4 as the output.Then, the 4th query deletes 4 from the heap, and the 5th query gives 9 as the output.

Minimum Average Waiting Time
Tieu owns a pizza restaurant and he manages it in his own way. While in a normal restaurant, a customer is served by following the first-come, first-served rule, Tieu simply minimizes the average waiting time of his customers. So he gets to decide who is served first, regardless of how sooner or later a person comes.
Different kinds of pizzas take different amounts of time to cook. Also, once he starts cooking a pizza, he cannot cook another pizza until the first pizza is completely cooked. Let's say we have three customers who come at time t=0, t=1, & t=2 respectively, and the time needed to cook their pizzas is 3, 9, & 6 respectively. If Tieu applies first-come, first-served rule, then the waiting time of three customers is 3, 11, & 16 respectively. The average waiting time in this case is (3 + 11 + 16) / 3 = 10. This is not an optimized solution. After serving the first customer at time t=3, Tieu can choose to serve the third customer. In that case, the waiting time will be 3, 7, & 17
respectively. Hence the average waiting time is (3 + 7 + 17) / 3 = 9. Help Tieu achieve the minimum average waiting time. For the sake of simplicity, just find the integer part of the minimum average waiting time.

Input Format
• The first line contains an integer N, which is the number of customers.
• In the next N line, the ith line contains two space separated numbers Ti and Li. Ti is the time when the ith customer order a pizza, and Li is the time required to cook that pizza.

Output Format
• Display the integer part of the minimum average waiting time.

Constraints
1 ≤ N ≤ 10^5
0 ≤ Ti ≤ 10^9
1 ≤ Li ≤ 10^9

Note
• The waiting time is calculated as the difference between the time a customer orders pizza (the time at which they enter the shop) and the time she is served.
• Cook does not know about the future orders.

Sample Input #00
3
0 3
1 9
2 6

Sample Output #00
9

Sample Input #01
3
0 3
1 9
2 5

Sample Output #01
8

Explanation #01
Let's call the person ordering at time = 0 as A, time = 1 as B and time = 2 as C. By delivering pizza for A, C and B we get the minimum average wait time to be
(3 + 6 + 16)/3 = 25/3 = 8.33
the integer part is 8 and hence the answer.

Reference no: EM131116560

Questions Cloud

Explain the various types of insurance : Explain the various types of insurance available to you. Which insurances are of most importance to you now - and why? And what insurances do you think you might need in the future - explain why?
Break-even point and target profit measured : Break-Even Point and Target Profit Measured in Sales Dollars (Multiple Products). Hi-Tech Incorporated produces two different products with the following monthly data (these data are the same as the previous exercise).
How the rate of teenage smoking in the united states : In contrast, macroeconomics is concerned with things that affect the country as a whole, such as how the rate of teenage smoking in the United States would be affected by an increase in the tax on cigarettes."
What is the critical path after the time reduction : A project manager is faced with the following activities and times associated with a building construction. Each activity can be crashed at most by 2 weeks. The cost associated with each week time reduction is given below. Which activities need to be..
Basic heap operations : Heap This question is designed to help you get a better understanding of basic heap operations. You will be given queries of 3 types:• "1 v" -Add an element v to the heap.• "2 v" -Delete the element v from the heap.• "3" -Print the minimum of all the..
Calculate the price elasticity of demand for winter wheat : Did the bumper harvest increase or decrease the total revenue of American wheat farmers? How could you have predicted this from your answer to part a?
Role of diversification of risk in forest management : This question is a short answer about the role of diversification of risk in forest management. Clearly state three unsystematic benefits and three unsystematic risks of investing in forestland relative to the global financial markets in general.
Does the software improve efficiency of business functions : You established a small shop that manufactures a single product that you sell by mail. You purchase raw materials from several vendors and employ five full-time employees. Describe the business functions that your shop would use software to perform? ..
High quality screw driver for home and professional use : XYZ company is considering making a capital investment of $175,000 that will allow them to produce a high quality screw driver for home and professional use. What is the lowest price that they can afford to sell these hammers? What should the price b..

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Draw the human encoding tree of these six characters

Show how to nd the maximum spanning tree of a graph, that is, the spanning tree of largest total weight.

  Draw the two points of intersection in red

Output: Draw a circle centered at with the given radius in a window with coordinates running from -10,-10 to 10,10. Draw a horizontal line across the window with the given y-intercept. Draw the two points of intersection in red. Print out the x va..

  Creating an idef1x diagram

Construct an IDEF1X diagram that demonstrate only entities and relationships. Name each relationship and specify its cardinalities.

  Analyze how the chart and pseudocode was created

Fill in the following table by walking through the logic above.The idea is to analyze how the chart and pseudocode was created, because you will be doing this in a few minutes

  Cloud computing assignment

WSDL service that receives a request for a stock market quote and returns the quote

  Let sbe the set of all people in the world for a b epsilon

let sbe the set of all people in the world. for a b epsilon s define a binary relation r as follows a b epsilon r if

  Illustrate how b-tree will expand

Illustrate how tree will expand (after inserting each Part#), and what the final tree would like. (b) Repeat item (a), but use a B-tree of order p = 4 instead of a B+-tree.

  Find the value of each given expression

Answer all the sub-questions for Problem 2 but for the following circular doubly-linked list with the two references P1 and P2: Find the value of each expression.

  Determine expected number of collisions use hash function

Assume we use hash function h to hash n distinct keys into the array T of length m. Suppose simple uniform hashing, determine the expected number of collisions?

  What are the characteristics of a good algorithm

What is an algorithm? What are the characteristics of a good algorithm and what do you mean by complexity of an algorithm? Explain the meaning of worst case analysis and best case analysis with an example.

  Write pseudocode of warshall algorithm

Write pseudocode of Warshall's algorithm assuming that the matrix rows are represented by bit strings on which the bitwise or operation can be performed

  Features of a database

What is a VIEW and what are its uses?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd