Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace TruckTour
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- public class Startup
- {
- public static void Main()
- {
- Queue<GasPump> allGasPumps = new Queue<GasPump>();
- int numberOfInputs = int.Parse(Console.ReadLine());
- for (int currInputLine = 0; currInputLine < numberOfInputs; currInputLine++)
- {
- allGasPumps.Enqueue(new GasPump(currInputLine, Console.ReadLine()
- .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray()));
- }
- int countOfPumpsPassedBy = 0;
- int gasPumpsToStopBy = allGasPumps.Count;
- int totalGasoline = 0;
- while (countOfPumpsPassedBy != gasPumpsToStopBy)
- {
- GasPump gasPump = allGasPumps.Dequeue();
- totalGasoline += gasPump.Gasoline;
- if (totalGasoline >= gasPump.DistanceToTravel)
- {
- totalGasoline -= gasPump.DistanceToTravel;
- countOfPumpsPassedBy++;
- }
- else
- {
- countOfPumpsPassedBy = 0;
- totalGasoline = 0;
- }
- allGasPumps.Enqueue(gasPump);
- }
- Console.WriteLine(allGasPumps.Peek().Index);
- }
- }
- public class GasPump
- {
- private int gasoline;
- private int distanceToTravel;
- private int index;
- public GasPump(int index, params int[] gasPumpInfo)
- {
- this.gasoline = gasPumpInfo[0];
- this.distanceToTravel = gasPumpInfo[1];
- this.index = index;
- }
- public int Gasoline
- {
- get { return this.gasoline; }
- set { this.gasoline = value; }
- }
- public int DistanceToTravel
- {
- get { return this.distanceToTravel; }
- set { this.distanceToTravel = value; }
- }
- public int Index
- {
- get { return this.index; }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement