Codeforces 151A Soft Drinking Solution & Explanation

Difficulty : 800

Problem Description

This winter is so cold in Nvodsk! A group of n friends decided to buy k bottles of a soft drink called “Take-It-Light” to warm up a bit. Each bottle has l milliliters of the drink. Also they bought c limes and cut each of them into d slices. After that they found p grams of salt.

To make a toast, each friend needs nl milliliters of the drink, a slice of lime and np grams of salt. The friends want to make as many toasts as they can, provided they all drink the same amount. How many toasts can each friend make?

Input

The first and only line contains positive integers nklcdpnlnp, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space.

Output

Print a single integer — the number of toasts each friend can make.

Examples

Input3 4 5 10 8 100 3 1
Output2
Input5 100 10 1 19 90 4 3
Output3
Input10 1000 1000 25 23 1 50 1
Output0

Note

A comment to the first sample:

Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is min(6, 80, 100) / 3 = 2.


Solution

This problem’s complexity mainly lies in the multitude of parameters. Let’s try adding comments individually for each of them.

C# Solution

Solution1

string[] arr = Console.ReadLine().Split(" ");
int n = int.Parse(arr[0]);  //number of friends
int k = int.Parse(arr[1]);  //bottles of a soft drink 
int l = int.Parse(arr[2]);  //milliliters of the drink
int c = int.Parse(arr[3]);  //limes
int d = int.Parse(arr[4]);  //slices of each limes
int p = int.Parse(arr[5]);  //grams of salt
int nl = int.Parse(arr[6]); //milliliters of the drink needed of a toast
int np = int.Parse(arr[7]); //grams of salt needed of a toast

int minNum = Math.Min(Math.Min(k*l/nl,c*d),p/np);   //number of toasts they can make
Console.WriteLine(minNum/n);

Math.Min(Math.Min(kl/nl,cd),p/np)

  • k * l / nl: Computes the maximum number of toasts that can be made from the soft drink, which is obtained by dividing the total volume of the soft drink (k * l) by the volume needed per toast (nl).
  • c * d: Computes the maximum number of toasts that can be made from the limes, where each lime is sliced into d pieces (with only one piece needed per toast).
  • p / np: Computes the maximum number of toasts that can be made from the salt, obtained by dividing the total weight of salt (p) by the weight needed per toast (np).

Then, the Math.Min() method is used to compare these three values and determine the minimum, representing the maximum number of toasts that can be made by the friends.


Conclusion

🧡If my solution helps, that is my honor!

🧡You can support me by sharing my posts, thanks you~~

✅If you got any problem about the explanation or you need other programming language solution, please feel free to let me know !!

The problem link : Problem – 151A – Codeforces

Random Codeforces Posts

Leave a Reply

Your email address will not be published. Required fields are marked *