Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Text;
- using System.Numerics;
- public class Program
- {
- public static void Main()
- {
- Dictionary<string,Dictionary<string,BigInteger>> typeNameValue = new Dictionary<string,Dictionary<string,BigInteger>>();
- BigInteger maxCapacity = BigInteger.Parse(Console.ReadLine());
- string[] itemsPairs = Console.ReadLine().Split(new char[]{' '},StringSplitOptions.RemoveEmptyEntries);
- for(int i=0; i<itemsPairs.Length; i+=2)
- {
- string currType = itemsPairs[i];
- BigInteger currQuantity = BigInteger.Parse(itemsPairs[i+1]);
- if(currType.ToLower()=="gold")
- {
- BigInteger currAmount = CurrSum(typeNameValue);
- if(currAmount+currQuantity<=maxCapacity)
- {
- if(!typeNameValue.ContainsKey("Gold"))
- {
- typeNameValue.Add("Gold",new Dictionary<string,BigInteger>());
- typeNameValue["Gold"].Add("Gold",currQuantity);
- }
- else
- {
- typeNameValue["Gold"]["Gold"]+=currQuantity;
- }
- }
- }
- else if (currType.ToLower().EndsWith("gem") && currType.Length>3)
- {
- BigInteger currAmount = CurrSum(typeNameValue);
- BigInteger currGoldAmount = AllGold(typeNameValue);
- BigInteger currGemAmount = AllGems(typeNameValue);
- if(currAmount+currQuantity<=maxCapacity && currGemAmount+currQuantity<=currGoldAmount)
- {
- if(!typeNameValue.ContainsKey("Gem"))
- {
- typeNameValue.Add("Gem",new Dictionary<string,BigInteger>());
- typeNameValue["Gem"].Add(currType,currQuantity);
- }
- else if (typeNameValue.ContainsKey("Gem")==true && typeNameValue["Gem"].ContainsKey(currType)==false)
- {
- typeNameValue["Gem"].Add(currType,currQuantity);
- }
- else if (typeNameValue.ContainsKey("Gem")==true && typeNameValue["Gem"].ContainsKey(currType)==true)
- {
- typeNameValue["Gem"][currType]+=currQuantity;
- }
- }
- }
- else if (currType.Length==3)
- {
- BigInteger currAmount = CurrSum(typeNameValue);
- BigInteger currGoldAmount = AllGold(typeNameValue);
- BigInteger currGemAmount = AllGems(typeNameValue);
- BigInteger currCashAmount = AllCash(typeNameValue);
- if(currAmount+currQuantity<=maxCapacity && currCashAmount + currQuantity<=currGemAmount)
- {
- if(!typeNameValue.ContainsKey("Cash"))
- {
- typeNameValue.Add("Cash",new Dictionary<string,BigInteger>());
- typeNameValue["Cash"].Add(currType,currQuantity);
- }
- else if (typeNameValue.ContainsKey("Cash") == true && typeNameValue["Cash"].ContainsKey(currType)==false)
- {
- typeNameValue["Cash"].Add(currType,currQuantity);
- }
- else if (typeNameValue.ContainsKey("Cash") == true && typeNameValue["Cash"].ContainsKey(currType)==true)
- {
- typeNameValue["Cash"][currType]+=currQuantity;
- }
- }
- }
- }
- if(typeNameValue.ContainsKey("Gold"))
- {
- var goldFiltered = typeNameValue["Gold"].OrderByDescending(x=>x.Key).ThenBy(x=>x.Value);
- BigInteger GoldAmount = AllGold(typeNameValue);
- Console.WriteLine("<{0}> ${1}","Gold",GoldAmount);
- foreach(var kvp in goldFiltered)
- {
- string item = kvp.Key;
- BigInteger quantity = kvp.Value;
- Console.WriteLine("##{0} - {1}",item,quantity);
- }
- }
- if(typeNameValue.ContainsKey("Gem"))
- {
- var gemFiltered = typeNameValue["Gem"].OrderByDescending(x=>x.Key).ThenBy(x=>x.Value);
- BigInteger GemAmount = AllGems(typeNameValue);
- Console.WriteLine("<{0}> ${1}","Gem",GemAmount);
- foreach(var kvp in gemFiltered)
- {
- string item = kvp.Key;
- BigInteger quantity = kvp.Value;
- Console.WriteLine("##{0} - {1}",item,quantity);
- }
- }
- if(typeNameValue.ContainsKey("Cash"))
- {
- var cashFiltered = typeNameValue["Cash"].OrderByDescending(x=>x.Key).ThenBy(x=>x.Value);
- BigInteger CashAmount = AllCash(typeNameValue);
- Console.WriteLine("<{0}> ${1}","Cash",CashAmount);
- foreach(var kvp in cashFiltered)
- {
- string item = kvp.Key;
- BigInteger quantity = kvp.Value;
- Console.WriteLine("##{0} - {1}",item,quantity);
- }
- }
- }
- public static BigInteger CurrSum(Dictionary<string,Dictionary<string,BigInteger>> typeNameValue)
- {
- BigInteger sum = 0;
- foreach(var kvp in typeNameValue)
- {
- string name = kvp.Key;
- foreach(var inner in kvp.Value)
- {
- BigInteger quantity = inner.Value;
- sum += quantity;
- }
- }
- return sum;
- }
- public static BigInteger AllGold(Dictionary<string,Dictionary<string,BigInteger>> typeNameValue)
- {
- BigInteger goldSum = 0;
- foreach(var kvp in typeNameValue)
- {
- string name = kvp.Key;
- if(name.ToLower()=="gold")
- {
- foreach(var inner in kvp.Value)
- {
- BigInteger quantity = inner.Value;
- goldSum += quantity;
- }
- }
- }
- return goldSum;
- }
- public static BigInteger AllGems(Dictionary<string,Dictionary<string,BigInteger>> typeNameValue)
- {
- BigInteger gemSum = 0;
- foreach(var kvp in typeNameValue)
- {
- string name = kvp.Key;
- if(name.ToLower()=="gem")
- {
- foreach(var inner in kvp.Value)
- {
- BigInteger quantity = inner.Value;
- gemSum += quantity;
- }
- }
- }
- return gemSum;
- }
- public static BigInteger AllCash(Dictionary<string,Dictionary<string,BigInteger>> typeNameValue)
- {
- BigInteger cashSum = 0;
- foreach(var kvp in typeNameValue)
- {
- string name = kvp.Key;
- if(name=="Cash")
- {
- foreach(var inner in kvp.Value)
- {
- BigInteger quantity = inner.Value;
- cashSum += quantity;
- }
- }
- }
- return cashSum;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment