Advertisement
bullit3189

GreedyTimes

Jun 6th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.69 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using System.Numerics;
  6.  
  7. public class Program
  8. {
  9. public static void Main()
  10. {
  11. Dictionary<string,Dictionary<string,BigInteger>> typeNameValue = new Dictionary<string,Dictionary<string,BigInteger>>();
  12.  
  13. BigInteger maxCapacity = BigInteger.Parse(Console.ReadLine());
  14.  
  15. string[] itemsPairs = Console.ReadLine().Split(new char[]{' '},StringSplitOptions.RemoveEmptyEntries);
  16.  
  17. for(int i=0; i<itemsPairs.Length; i+=2)
  18. {
  19. string currType = itemsPairs[i];
  20. BigInteger currQuantity = BigInteger.Parse(itemsPairs[i+1]);
  21.  
  22. if(currType.ToLower()=="gold")
  23. {
  24. BigInteger currAmount = CurrSum(typeNameValue);
  25.  
  26. if(currAmount+currQuantity<=maxCapacity)
  27. {
  28. if(!typeNameValue.ContainsKey("Gold"))
  29. {
  30. typeNameValue.Add("Gold",new Dictionary<string,BigInteger>());
  31. typeNameValue["Gold"].Add("Gold",currQuantity);
  32. }
  33. else
  34. {
  35. typeNameValue["Gold"]["Gold"]+=currQuantity;
  36. }
  37. }
  38. }
  39. else if (currType.ToLower().EndsWith("gem") && currType.Length>3)
  40. {
  41. BigInteger currAmount = CurrSum(typeNameValue);
  42. BigInteger currGoldAmount = AllGold(typeNameValue);
  43. BigInteger currGemAmount = AllGems(typeNameValue);
  44.  
  45. if(currAmount+currQuantity<=maxCapacity && currGemAmount+currQuantity<=currGoldAmount)
  46. {
  47. if(!typeNameValue.ContainsKey("Gem"))
  48. {
  49. typeNameValue.Add("Gem",new Dictionary<string,BigInteger>());
  50. typeNameValue["Gem"].Add(currType,currQuantity);
  51. }
  52. else if (typeNameValue.ContainsKey("Gem")==true && typeNameValue["Gem"].ContainsKey(currType)==false)
  53. {
  54. typeNameValue["Gem"].Add(currType,currQuantity);
  55. }
  56. else if (typeNameValue.ContainsKey("Gem")==true && typeNameValue["Gem"].ContainsKey(currType)==true)
  57. {
  58. typeNameValue["Gem"][currType]+=currQuantity;
  59. }
  60. }
  61. }
  62. else if (currType.Length==3)
  63. {
  64. BigInteger currAmount = CurrSum(typeNameValue);
  65. BigInteger currGoldAmount = AllGold(typeNameValue);
  66. BigInteger currGemAmount = AllGems(typeNameValue);
  67. BigInteger currCashAmount = AllCash(typeNameValue);
  68.  
  69. if(currAmount+currQuantity<=maxCapacity && currCashAmount + currQuantity<=currGemAmount)
  70. {
  71. if(!typeNameValue.ContainsKey("Cash"))
  72. {
  73. typeNameValue.Add("Cash",new Dictionary<string,BigInteger>());
  74. typeNameValue["Cash"].Add(currType,currQuantity);
  75. }
  76. else if (typeNameValue.ContainsKey("Cash") == true && typeNameValue["Cash"].ContainsKey(currType)==false)
  77. {
  78. typeNameValue["Cash"].Add(currType,currQuantity);
  79. }
  80. else if (typeNameValue.ContainsKey("Cash") == true && typeNameValue["Cash"].ContainsKey(currType)==true)
  81. {
  82. typeNameValue["Cash"][currType]+=currQuantity;
  83. }
  84. }
  85. }
  86. }
  87.  
  88. if(typeNameValue.ContainsKey("Gold"))
  89. {
  90. var goldFiltered = typeNameValue["Gold"].OrderByDescending(x=>x.Key).ThenBy(x=>x.Value);
  91.  
  92. BigInteger GoldAmount = AllGold(typeNameValue);
  93. Console.WriteLine("<{0}> ${1}","Gold",GoldAmount);
  94.  
  95. foreach(var kvp in goldFiltered)
  96. {
  97. string item = kvp.Key;
  98. BigInteger quantity = kvp.Value;
  99.  
  100. Console.WriteLine("##{0} - {1}",item,quantity);
  101. }
  102. }
  103.  
  104. if(typeNameValue.ContainsKey("Gem"))
  105. {
  106. var gemFiltered = typeNameValue["Gem"].OrderByDescending(x=>x.Key).ThenBy(x=>x.Value);
  107.  
  108. BigInteger GemAmount = AllGems(typeNameValue);
  109. Console.WriteLine("<{0}> ${1}","Gem",GemAmount);
  110.  
  111. foreach(var kvp in gemFiltered)
  112. {
  113. string item = kvp.Key;
  114. BigInteger quantity = kvp.Value;
  115.  
  116. Console.WriteLine("##{0} - {1}",item,quantity);
  117. }
  118. }
  119.  
  120. if(typeNameValue.ContainsKey("Cash"))
  121. {
  122. var cashFiltered = typeNameValue["Cash"].OrderByDescending(x=>x.Key).ThenBy(x=>x.Value);
  123.  
  124. BigInteger CashAmount = AllCash(typeNameValue);
  125. Console.WriteLine("<{0}> ${1}","Cash",CashAmount);
  126.  
  127. foreach(var kvp in cashFiltered)
  128. {
  129. string item = kvp.Key;
  130. BigInteger quantity = kvp.Value;
  131.  
  132. Console.WriteLine("##{0} - {1}",item,quantity);
  133. }
  134. }
  135.  
  136. }
  137.  
  138. public static BigInteger CurrSum(Dictionary<string,Dictionary<string,BigInteger>> typeNameValue)
  139. {
  140. BigInteger sum = 0;
  141.  
  142. foreach(var kvp in typeNameValue)
  143. {
  144. string name = kvp.Key;
  145.  
  146. foreach(var inner in kvp.Value)
  147. {
  148. BigInteger quantity = inner.Value;
  149.  
  150. sum += quantity;
  151. }
  152. }
  153.  
  154. return sum;
  155. }
  156.  
  157. public static BigInteger AllGold(Dictionary<string,Dictionary<string,BigInteger>> typeNameValue)
  158. {
  159. BigInteger goldSum = 0;
  160.  
  161. foreach(var kvp in typeNameValue)
  162. {
  163. string name = kvp.Key;
  164.  
  165. if(name.ToLower()=="gold")
  166. {
  167. foreach(var inner in kvp.Value)
  168. {
  169. BigInteger quantity = inner.Value;
  170.  
  171. goldSum += quantity;
  172. }
  173. }
  174. }
  175.  
  176. return goldSum;
  177. }
  178. public static BigInteger AllGems(Dictionary<string,Dictionary<string,BigInteger>> typeNameValue)
  179. {
  180. BigInteger gemSum = 0;
  181.  
  182. foreach(var kvp in typeNameValue)
  183. {
  184. string name = kvp.Key;
  185.  
  186. if(name.ToLower()=="gem")
  187. {
  188. foreach(var inner in kvp.Value)
  189. {
  190. BigInteger quantity = inner.Value;
  191.  
  192. gemSum += quantity;
  193. }
  194. }
  195. }
  196.  
  197. return gemSum;
  198. }
  199. public static BigInteger AllCash(Dictionary<string,Dictionary<string,BigInteger>> typeNameValue)
  200. {
  201. BigInteger cashSum = 0;
  202.  
  203. foreach(var kvp in typeNameValue)
  204. {
  205. string name = kvp.Key;
  206.  
  207. if(name=="Cash")
  208. {
  209. foreach(var inner in kvp.Value)
  210. {
  211. BigInteger quantity = inner.Value;
  212.  
  213. cashSum += quantity;
  214. }
  215. }
  216. }
  217. return cashSum;
  218. }
  219. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement