AlgoUniversity
  • Go Back
Discussion
VM Pricing :

Author

Yash Sahijwani

Difficulty Level : Easy

Submissions : 289

Asked In : Gameskraft

Marks :50

: 3 | : 2

A cloud service provider offers quantity discounts based on the number of virtual machines a customer needs. Their offerings vary from 2 to 2000 instances. When pricing is requested, the customer's representative refers to a list of past pricing. Given a list of past price quotes and the number of instances a customer needs, determine the per-instance price for the customer.

The method for determining price is as follows:

  • If the number of instances needed is exactly the same as the quantity for a prior customer, the unit price is that price.
  • If there is a price for a larger number and a price for a smaller number of instances, linearly interpolate the price of the quantity needed from the unit prices for the closest smaller and larger quantities.
  • If the quantities for which there is past data are all smaller or all larger than the amount needed, then linearly extrapolate the unit price from the 2 points closest to the quantity needed.
  • If the database only has 1 quantity, that is the price per unit.
  • Sometimes, price quotes lapse. When that happens, the old pricing is overwritten with either a 0 or a negative number. The quantities associated with zero or negative unit prices must be disregarded.

Input

The first line of input consists of a single integer $$$n$$$ $$$(1 \leq n \leq 2000)$$$ $$$-$$$ the number of instances the customer needs. The second line of input consists of a single integer $$$m$$$ $$$(1 \leq m \leq 10^5)$$$ $$$-$$$ the total number of past prices. The third line consists of $$$m$$$ space separated integers $$$-$$$ where the $$$i_{th}$$$ integer represents $$$instances[i]$$$. The fourth line consists of $$$m$$$ space separated floating point numbers $$$-$$$ where the $$$i_{th}$$$ number represents $$$price[i]$$$.

Output

Output a single floating point number $$$-$$$ the per instance price, which should be precise upto 6 decimal places.

Examples

Input
75
3
25 50 100
5.0 4.0 3.0
Output
3.500000
Input
25
5
10 25 50 100 500
2.46 2.58 2.0 2.25 3.0
Output
2.58

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.