Advertisement
Guest User

Untitled

a guest
Apr 11th, 2020
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace _07_Truck_Tour
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int n = int.Parse(Console.ReadLine());
  12.  
  13. var queueTruck = new Queue<int>();
  14.  
  15. int sum = 0;
  16.  
  17. for (int i = 0; i < n; i++)
  18. {
  19. var information = Console.ReadLine()
  20. .Split()
  21. .Select(int.Parse)
  22. .ToArray();
  23. int amountOfPetrol = information[0];
  24. int distance = information[1];
  25.  
  26. queueTruck.Enqueue(amountOfPetrol - distance);
  27. }
  28.  
  29. for (int i = 0; i < n; i++)
  30. {
  31. if (queueTruck.Peek() >= 0)
  32. {
  33. foreach (var elm in queueTruck)
  34. {
  35. sum += elm;
  36. if (sum < 0)
  37. {
  38. break;
  39. }
  40. }
  41.  
  42. if (sum>=0)
  43. {
  44. Console.WriteLine(i);
  45. return;
  46. }
  47. else
  48. {
  49. queueTruck.Enqueue(queueTruck.Peek());
  50. queueTruck.Dequeue();
  51. sum = 0;
  52. }
  53. }
  54. else
  55. {
  56. queueTruck.Enqueue(queueTruck.Peek());
  57. queueTruck.Dequeue();
  58. }
  59. }
  60. }
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement