Prohause

Problem 1 – Hogswatch

Aug 28th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. using System;
  2. using System.Xml;
  3.  
  4. namespace zada4a1
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. int homes = int.Parse(Console.ReadLine());
  11. int initialPresents = int.Parse(Console.ReadLine());
  12. int remainingPressents = initialPresents;
  13. int usedAdditionalPresents = 0;
  14. int trips = 0;
  15.  
  16. for (int i = 1; i <= homes; i++)
  17. {
  18. int neededPresents = int.Parse(Console.ReadLine());
  19. if (remainingPressents - neededPresents < 0)//когато не стигат подаръците
  20. {
  21. int additionalPresents = (initialPresents / i) * (homes - i) + (neededPresents - remainingPressents);
  22. remainingPressents += additionalPresents;
  23. usedAdditionalPresents += additionalPresents;
  24. trips++;
  25. }
  26.  
  27. remainingPressents -= neededPresents;
  28. }
  29.  
  30. if (trips>0)//ако е направил допълнителни разходки
  31. {
  32. Console.WriteLine(trips);
  33. Console.WriteLine(usedAdditionalPresents);
  34. }
  35. else
  36. {
  37. Console.WriteLine(remainingPressents);
  38. }
  39. }
  40. }
  41. }
Add Comment
Please, Sign In to add comment