Advertisement
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 Problem_3___Greedy_Times
- {
- class Program
- {
- class Ruby
- {
- public string UpperName { get; set; }
- public string NormalName { get; set; }
- public long Money { get; set; }
- }
- static void Main(string[] args)
- {
- long allCapacity = long.Parse(Console.ReadLine());
- var book = new Dictionary<string, List<Ruby>>();
- book["Gold"] = new List<Ruby>();
- book["Gem"] = new List<Ruby>();
- book["Cash"] = new List<Ruby>();
- var input = Console.ReadLine().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToArray();
- for (int i = 0; i < input.Length; i += 2)
- {
- var name = input[i].ToUpper();
- var money = long.Parse(input[i + 1]);
- var bagCount = book["Gold"].Sum(a => a.Money) + book["Gem"].Sum(a => a.Money) + book["Cash"].Sum(a => a.Money);
- if (allCapacity < bagCount + money)
- {
- continue;
- }
- if (name == "GOLD")
- {
- if (book["Gold"].All(a => a.UpperName != name))
- {
- var currentItem = new Ruby
- {
- UpperName = name,
- NormalName = input[i],
- Money = money
- };
- book["Gold"].Add(currentItem);
- }
- else
- {
- foreach (var item in book["Gold"])
- {
- if (item.UpperName == name)
- {
- item.Money += money;
- }
- }
- }
- }
- else if (name.EndsWith("GEM") && name.Length > 3)
- {
- if (book["Gold"].Sum(a => a.Money) < book["Gem"].Sum(a => a.Money) + money)
- {
- continue;
- }
- if (book["Gem"].All(a => a.UpperName != name))
- {
- var currentItem = new Ruby
- {
- UpperName = name,
- NormalName = input[i],
- Money = money
- };
- book["Gem"].Add(currentItem);
- }
- else
- {
- foreach (var item in book["Gem"])
- {
- if (item.UpperName == name)
- {
- item.Money += money;
- }
- }
- }
- }
- else if (name.Length == 3)
- {
- if (book["Gem"].Sum(a => a.Money) < book["Cash"].Sum(a => a.Money) + money)
- {
- continue;
- }
- if (book["Cash"].All(a => a.UpperName != name))
- {
- var currentItem = new Ruby
- {
- UpperName = name,
- NormalName = input[i],
- Money = money
- };
- book["Cash"].Add(currentItem);
- }
- else
- {
- foreach (var item in book["Cash"])
- {
- if (item.UpperName == name)
- {
- item.Money += money;
- }
- }
- }
- }
- }
- foreach (var item in book.OrderByDescending(a => a.Value.Sum(p => p.Money)))
- {
- if (item.Value.Sum(a => a.Money) > 0)
- {
- Console.WriteLine($"<{item.Key}> ${item.Value.Sum(p => p.Money)}");
- foreach (var item2 in item.Value.OrderByDescending(a => a.NormalName).ThenBy(a => a.Money))
- {
- Console.WriteLine($"##{item2.NormalName} - {item2.Money}");
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement