Guest User

Untitled

a guest
Jul 5th, 2019
702
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace TruckTour
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int n = int.Parse(Console.ReadLine());
  12. var petrol = new Queue<int>();
  13. var distance = new Queue<int>();
  14. int[] input;
  15. for (int i = 0; i < n; i++)
  16. {
  17. input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  18. petrol.Enqueue(input[0]);
  19. distance.Enqueue(input[1]);
  20. }
  21. int currentFuel;
  22. var petrolCopy = new Queue<int>();
  23. var distanceCopy = new Queue<int>();
  24. for (int i = 0; i < n; i++)
  25. {
  26. currentFuel=petrol.Peek();
  27. petrolCopy = new Queue<int>(petrol);
  28. distanceCopy = new Queue<int>(distance);
  29. for (int x = 0; x < n; x++)
  30. {
  31. if (distanceCopy.Peek() <= currentFuel)
  32. {
  33. currentFuel -= distanceCopy.Peek();
  34. if (x == n - 1)
  35. {
  36. Console.WriteLine(i);
  37. return;
  38. }
  39. }
  40. else
  41. {
  42. break;
  43. }
  44. petrolCopy.Enqueue(petrolCopy.Dequeue());
  45. distanceCopy.Enqueue(distanceCopy.Dequeue());
  46. currentFuel += petrolCopy.Peek();
  47. }
  48. petrol.Enqueue(petrol.Dequeue());
  49. distance.Enqueue(distance.Dequeue());
  50. }
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment