bullit3189

Hogswatch-TF-MidExam27Aug18

Jan 29th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace _01Hogswatch
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int homesToVisit = int.Parse(Console.ReadLine());
  12. int initalPresents = int.Parse(Console.ReadLine());
  13.  
  14. int copyOfInitial = initalPresents;
  15. int tookInAddition = 0;
  16.  
  17. int comeback = 0;
  18.  
  19. for (int i = 1; i <= homesToVisit; i++)
  20. {
  21. int childPerHouse = int.Parse(Console.ReadLine());
  22.  
  23. initalPresents -= childPerHouse;
  24.  
  25. if (initalPresents<0)
  26. {
  27. comeback++;
  28. int additionalPresents = Math.Abs(initalPresents);
  29. initalPresents = 0;
  30. initalPresents += (copyOfInitial / i) * (homesToVisit - i) + additionalPresents;
  31. tookInAddition += initalPresents;
  32. initalPresents -= additionalPresents;
  33. }
  34. }
  35.  
  36. if (comeback==0)
  37. {
  38. Console.WriteLine(initalPresents);
  39. }
  40. else
  41. {
  42. Console.WriteLine(comeback);
  43. Console.WriteLine(tookInAddition);
  44. }
  45. }
  46. }
  47. }
Add Comment
Please, Sign In to add comment