Advertisement
Mechoboy

Untitled

Jun 11th, 2016
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 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.  
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. double supply = double.Parse(Console.ReadLine());
  13. double a = supply;
  14. double[] bottles = Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
  15. double capacity = double.Parse(Console.ReadLine());
  16. double numberOfBottles = 0;
  17. bool filledBottles = false;
  18. List<long> indexes = new List<long>();
  19. double littersNeeded = 0;
  20. if (supply % 2 != 0)
  21. {
  22. for (int i = bottles.Length - 1; i >= 0; i--)
  23. {
  24. if (bottles[i] <= capacity && supply > 0)
  25. {
  26. if (supply < capacity - bottles[i])
  27. {
  28. bottles[i] += supply;
  29. break;
  30. }
  31. supply -= (capacity - bottles[i]);
  32. bottles[i] += (capacity - bottles[i]);
  33. }
  34. if (bottles[0] == capacity && supply >= 0)
  35. {
  36. Console.WriteLine("Enough water!");
  37. Console.WriteLine("Water left: {0}l.", supply);
  38. filledBottles = true;
  39. }
  40. }
  41. if (!filledBottles)
  42. {
  43. for (int i = bottles.Length - 1; i >= 0; i--)
  44. {
  45. if (bottles[i] < capacity)
  46. {
  47. numberOfBottles++;
  48. littersNeeded += (capacity - bottles[i]);
  49. indexes.Add(i);
  50. }
  51. if (i == 0)
  52. {
  53. Console.WriteLine("We need more water!");
  54. Console.WriteLine("Bottles left: {0}", numberOfBottles);
  55. string joined = string.Join<long>(", ", indexes);
  56. Console.WriteLine("With indexes: " + joined);
  57. Console.WriteLine("We need {0} more liters!", littersNeeded);
  58. }
  59. }
  60. }
  61. }
  62. if (supply % 2 == 0 && supply == a)
  63. {
  64. for (int i = 0; i < bottles.Length; i++)
  65. {
  66. if (bottles[i] <= capacity && supply > 0)
  67. {
  68. if (supply < capacity - bottles[i])
  69. {
  70. bottles[i] += supply;
  71. break;
  72. }
  73. supply -= (capacity - bottles[i]);
  74. bottles[i] += (capacity - bottles[i]);
  75. }
  76. if (bottles[bottles.Length - 1] == capacity && supply >= 0)
  77. {
  78. Console.WriteLine("Enough water!");
  79. Console.WriteLine("Water left: {0}l.", supply);
  80. filledBottles = true;
  81. }
  82. }
  83. if (!filledBottles)
  84. {
  85. for (int i = 0; i < bottles.Length; i++)
  86. {
  87. if (bottles[i] < capacity)
  88. {
  89. numberOfBottles++;
  90. littersNeeded += (capacity - bottles[i]);
  91. indexes.Add(i);
  92. }
  93. if (i == bottles.Length - 1)
  94. {
  95. Console.WriteLine("We need more water!");
  96. Console.WriteLine("Bottles left: {0}", numberOfBottles);
  97. string joined = string.Join<long>(", ", indexes);
  98. Console.WriteLine("With indexes: " + joined);
  99. Console.WriteLine("We need {0} more liters!", littersNeeded);
  100. }
  101. }
  102. }
  103. }
  104. }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement