Advertisement
gabi11

Stacks and Queues - 07. Truck Tour

May 10th, 2019
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7. namespace Advanced
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int numberOfPumps = int.Parse(Console.ReadLine());
  14.             var pumpIndex = new Queue<int>();
  15.  
  16.             var fuel = 0;
  17.  
  18.             for (int i = 0; i < numberOfPumps; i++)
  19.             {
  20.                 var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
  21.  
  22.                 var pompCapacity = input[0];
  23.                 var distance = input[1];
  24.  
  25.                 fuel += pompCapacity;
  26.  
  27.                 if (fuel >= distance)
  28.                 {
  29.                     pumpIndex.Enqueue(i);
  30.                     fuel -= distance;
  31.                 }
  32.                 else
  33.                 {
  34.                     pumpIndex.Clear();
  35.                     fuel = 0;
  36.                 }
  37.             }
  38.             Console.WriteLine(pumpIndex.Min());
  39.  
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement