Advertisement
YORDAN2347

TruckTour

Feb 9th, 2021
671
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _07._TruckTour
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int n = int.Parse(Console.ReadLine());
  12.  
  13.             string[] pumpStations = new string[n];
  14.  
  15.             for (int i = 0; i < n; i++)
  16.             {
  17.                 pumpStations[i] = Console.ReadLine();
  18.             }
  19.             Queue<string> pumps = new Queue<string>(pumpStations);
  20.  
  21.            
  22.             for (int i = 0; i < n; i++)
  23.             {
  24.                 bool isValid = true;
  25.                 int tank = 0;
  26.                 for (int j = 0; j < n; j++)
  27.                 {
  28.                     string station = pumps.Dequeue();
  29.                     int[] paramaters = station.Split().Select(int.Parse).ToArray();
  30.                     int fuel = paramaters[0];
  31.                     int distance = paramaters[1];
  32.                     tank += fuel;
  33.                     tank -= distance;
  34.                     if (tank < 0)
  35.                     {
  36.                         isValid = false;
  37.                     }
  38.                     pumps.Enqueue(station);
  39.                    
  40.                 }
  41.                 if (isValid)
  42.                 {
  43.                     Console.WriteLine(i);
  44.                     return;
  45.                 }
  46.                 pumps.Enqueue(pumps.Dequeue());
  47.             }
  48.         }
  49.     }
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement