Advertisement
Prohause

Untitled

May 21st, 2016
892
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class TruckTour
  6. {
  7. static void Main( )
  8. {
  9. long stops = long.Parse(Console.ReadLine());
  10. Queue<string> myQueue = new Queue<string>();
  11.  
  12. for ( long i = 0;i < stops;i++ )
  13. {
  14. myQueue.Enqueue( Console.ReadLine( ) );
  15. }
  16.  
  17. bool canMakeIt= false;
  18.  
  19.  
  20. for ( long i = 0;i < stops;i++ )
  21. {
  22. long fuel = 0;
  23. foreach ( var item in myQueue )
  24. {
  25. fuel += item.Trim( ).Split( new char[] { ' ' },StringSplitOptions.RemoveEmptyEntries ).Select( long.Parse ).ToArray( )[0];
  26. fuel -= item.Trim( ).Split( new char[] { ' ' },StringSplitOptions.RemoveEmptyEntries ).Select( long.Parse ).ToArray( )[1];
  27. if ( fuel <=0 )
  28. {
  29. canMakeIt = false;
  30. break;
  31. }
  32. else
  33. {
  34. canMakeIt = true;
  35. }
  36. }
  37. if ( canMakeIt )
  38. {
  39. Console.WriteLine(i);
  40. return;
  41. }
  42. string helper = myQueue.Dequeue();
  43. myQueue.Enqueue( helper );
  44.  
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement