Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

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.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M91874133
  • Price:- $30

Priced at Now at $30, Verified Solution

Have any Question?


Related Questions in Computer Engineering

A simple repetitive song with varying verse the ants go

A simple repetitive song with varying verse, "The Ants Go Marching" provides a simple assignment for remembering the basic Control Structures - loops, switch statements, if-then-else statements, etc., that you learned in ...

Is smartart graphic and table slide important for

Is Smartart graphic and Table slide important for PowerPoint Presentation? How would it benefit?

1 select one of the topics listed below and discuss

1. Select one of the topics listed below and discuss it. Describe an application that you have to solve by using at least 2 Excel functions. It can be Math, Statistics, Engineering, Financial, etc. Explain what Excel fun ...

What is the various security architectures which provides

What is the various security architectures. Which provides the best balance between simplicity and security? Justify your answer.

Question 1 with the explosion of users on social media

Question: 1. With the explosion of users on social media sites, businesses need to establish their presence on social media sites. Just search for "Vans" or "Starbucks" on Facebook for examples of company sites. To manag ...

Requirementsin this assignment you will implement a

Requirements In this assignment, you will implement a lightweight version of an ArrayList class. You may refer to the Java code and documentation for guidance, but you must write the implementation yourself. Additionally ...

Please tell me about planning and installing a wireless

Please tell me about Planning and Installing a Wireless Network

Question three academically reviewed articles on management

Question: Three academically reviewed articles on Management Information Systems and complete the following activities: 1. Summarize all three (3) articles in 600 words or more in APA format with reference 2. Discuss at ...

Question suppose now that after each turn a single six-face

Question : Suppose now that after each turn, a single six-face die is tossed. If it comes out to one, a single chip is removed from the fourth pile; otherwise, the board is left as is. Describe an efficient algorithm tha ...

Question suppose you are asked to automate the prescription

Question : Suppose you are asked to automate the prescription fulfillment system for a pharmacy, MailDrugs. When an order comes in, it is given as a sequence of requests, "x1 ml of drug y1," "x2 ml of drug y2," "x3 ml of ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As