Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _08_diet
- {
- class Program
- {
- static void Main()
- {
- int Raspberries = int.Parse(Console.ReadLine());
- int Strawberries = int.Parse(Console.ReadLine());
- int Cherries = int.Parse(Console.ReadLine());
- int neededJuice = int.Parse(Console.ReadLine());
- var fruitJuice = new Dictionary<string, double>()
- {
- { "Raspberries", 4.5 }, { "Strawberries", 7.5 }, { "Cherries", 15 }
- };
- var totalCombinations = new List<Dictionary<string, int>>(1024);
- double local = 0;
- double max = 0;
- int maxCherries = Math.Min(Cherries, neededJuice / 15);
- int maxStrawberries = Math.Min(Strawberries, (int)(neededJuice / 7.5));
- int maxRaspberries = Math.Min(Raspberries, (int)(neededJuice / 4.5));
- for (int i = 0; i <= Raspberries; i++)
- {
- for (int j = 0; j <= maxStrawberries; j++)
- {
- for (int k = 0; k <= maxCherries; k++)
- {
- local = i * fruitJuice["Raspberries"] + j * fruitJuice["Strawberries"] + k * fruitJuice["Cherries"];
- if (local <= neededJuice && local >= max)
- {
- max = local;
- var tmp = new Dictionary<string, int>()
- {
- { "Raspberries", i }, { "Strawberries", j }, { "Cherries", k }
- };
- totalCombinations.Add(tmp);
- }
- if (local > neededJuice)
- {
- break;
- }
- }
- }
- }
- foreach (var combination in totalCombinations)
- {
- double total = 0;
- foreach (var item in combination)
- {
- string fruit = item.Key;
- int quantity = item.Value;
- total += quantity * fruitJuice[fruit];
- }
- if (total == max)
- {
- Console.WriteLine($"{combination["Raspberries"]} Raspberries, {combination["Strawberries"]} Strawberries," +
- $" {combination["Cherries"]} Cherries. Juice: {max} ml.");
- break;
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment