Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
572
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.67 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Problem_3___Greedy_Times
  8. {
  9. class Program
  10. {
  11. class Ruby
  12. {
  13. public string UpperName { get; set; }
  14. public string NormalName { get; set; }
  15. public long Money { get; set; }
  16. }
  17.  
  18.  
  19. static void Main(string[] args)
  20. {
  21. long allCapacity = long.Parse(Console.ReadLine());
  22. var book = new Dictionary<string, List<Ruby>>();
  23. book["Gold"] = new List<Ruby>();
  24. book["Gem"] = new List<Ruby>();
  25. book["Cash"] = new List<Ruby>();
  26. var input = Console.ReadLine().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  27.  
  28. for (int i = 0; i < input.Length; i += 2)
  29. {
  30. var name = input[i].ToUpper();
  31. var money = long.Parse(input[i + 1]);
  32.  
  33. var bagCount = book["Gold"].Sum(a => a.Money) + book["Gem"].Sum(a => a.Money) + book["Cash"].Sum(a => a.Money);
  34.  
  35. if (allCapacity < bagCount + money)
  36. {
  37. continue;
  38. }
  39.  
  40. if (name == "GOLD")
  41. {
  42. if (book["Gold"].All(a => a.UpperName != name))
  43. {
  44. var currentItem = new Ruby
  45. {
  46. UpperName = name,
  47. NormalName = input[i],
  48. Money = money
  49. };
  50. book["Gold"].Add(currentItem);
  51. }
  52. else
  53. {
  54. foreach (var item in book["Gold"])
  55. {
  56. if (item.UpperName == name)
  57. {
  58. item.Money += money;
  59. }
  60. }
  61. }
  62. }
  63. else if (name.EndsWith("GEM") && name.Length > 3)
  64. {
  65. if (book["Gold"].Sum(a => a.Money) < book["Gem"].Sum(a => a.Money) + money)
  66. {
  67. continue;
  68. }
  69.  
  70. if (book["Gem"].All(a => a.UpperName != name))
  71. {
  72. var currentItem = new Ruby
  73. {
  74. UpperName = name,
  75. NormalName = input[i],
  76. Money = money
  77. };
  78. book["Gem"].Add(currentItem);
  79. }
  80. else
  81. {
  82. foreach (var item in book["Gem"])
  83. {
  84. if (item.UpperName == name)
  85. {
  86. item.Money += money;
  87. }
  88. }
  89. }
  90. }
  91. else if (name.Length == 3)
  92. {
  93. if (book["Gem"].Sum(a => a.Money) < book["Cash"].Sum(a => a.Money) + money)
  94. {
  95. continue;
  96. }
  97.  
  98. if (book["Cash"].All(a => a.UpperName != name))
  99. {
  100. var currentItem = new Ruby
  101. {
  102. UpperName = name,
  103. NormalName = input[i],
  104. Money = money
  105. };
  106. book["Cash"].Add(currentItem);
  107. }
  108. else
  109. {
  110. foreach (var item in book["Cash"])
  111. {
  112. if (item.UpperName == name)
  113. {
  114. item.Money += money;
  115. }
  116. }
  117. }
  118. }
  119. }
  120.  
  121. foreach (var item in book.OrderByDescending(a => a.Value.Sum(p => p.Money)))
  122. {
  123. if (item.Value.Sum(a => a.Money) > 0)
  124. {
  125. Console.WriteLine($"<{item.Key}> ${item.Value.Sum(p => p.Money)}");
  126.  
  127. foreach (var item2 in item.Value.OrderByDescending(a => a.NormalName).ThenBy(a => a.Money))
  128. {
  129. Console.WriteLine($"##{item2.NormalName} - {item2.Money}");
  130. }
  131. }
  132. }
  133. }
  134. }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement