Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace P05_GreedyTimes
  6. {
  7.  
  8. public class Potato
  9. {
  10. static void Main(string[] args)
  11. {
  12. long vhod = long.Parse(Console.ReadLine());
  13. string[] seif = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  14.  
  15. var torba = new Dictionary<string, Dictionary<string, long>>();
  16. long zlato = 0;
  17. long kamuni = 0;
  18. long mangizi = 0;
  19.  
  20. for (int i = 0; i < seif.Length; i += 2)
  21. {
  22. string name = seif[i];
  23. long broika = long.Parse(seif[i + 1]);
  24.  
  25. string kvoE = string.Empty;
  26.  
  27. if (name.Length == 3)
  28. {
  29. kvoE = "Cash";
  30. }
  31. else if (name.ToLower().EndsWith("gem"))
  32. {
  33. kvoE = "Gem";
  34. }
  35. else if (name.ToLower() == "gold")
  36. {
  37. kvoE = "Gold";
  38. }
  39.  
  40. if (kvoE == "")
  41. {
  42. continue;
  43. }
  44. else if (vhod < torba.Values.Select(x => x.Values.Sum()).Sum() + broika)
  45. {
  46. continue;
  47. }
  48.  
  49. switch (kvoE)
  50. {
  51. case "Gem":
  52. if (!torba.ContainsKey(kvoE))
  53. {
  54. if (torba.ContainsKey("Gold"))
  55. {
  56. if (broika > torba["Gold"].Values.Sum())
  57. {
  58. continue;
  59. }
  60. }
  61. else
  62. {
  63. continue;
  64. }
  65. }
  66. else if (torba[kvoE].Values.Sum() + broika > torba["Gold"].Values.Sum())
  67. {
  68. continue;
  69. }
  70. break;
  71. case "Cash":
  72. if (!torba.ContainsKey(kvoE))
  73. {
  74. if (torba.ContainsKey("Gem"))
  75. {
  76. if (broika > torba["Gem"].Values.Sum())
  77. {
  78. continue;
  79. }
  80. }
  81. else
  82. {
  83. continue;
  84. }
  85. }
  86. else if (torba[kvoE].Values.Sum() + broika > torba["Gem"].Values.Sum())
  87. {
  88. continue;
  89. }
  90. break;
  91. }
  92.  
  93. if (!torba.ContainsKey(kvoE))
  94. {
  95. torba[kvoE] = new Dictionary<string, long>();
  96. }
  97.  
  98. if (!torba[kvoE].ContainsKey(name))
  99. {
  100. torba[kvoE][name] = 0;
  101. }
  102.  
  103. torba[kvoE][name] += broika;
  104. if (kvoE == "Gold")
  105. {
  106. zlato += broika;
  107. }
  108. else if (kvoE == "Gem")
  109. {
  110. kamuni += broika;
  111. }
  112. else if (kvoE == "Cash")
  113. {
  114. mangizi += broika;
  115. }
  116. }
  117.  
  118. foreach (var x in torba)
  119. {
  120. Console.WriteLine($"<{x.Key}> ${x.Value.Values.Sum()}");
  121. foreach (var item2 in x.Value.OrderByDescending(y => y.Key).ThenBy(y => y.Value))
  122. {
  123. Console.WriteLine($"##{item2.Key} - {item2.Value}");
  124. }
  125. }
  126. }
  127. }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement