Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Truck_Tour
- {
- class Pump
- {
- public Pump()
- {
- }// Pump()
- public Pump(int newNum, int newFuel, int newDistanceToNextPump)
- {
- this.Num = newNum;
- this.Fuel = newFuel;
- this.DistanceToNextPump = newDistanceToNextPump;
- }
- public int Num { get; set; }
- public int Fuel { get; set; }
- public int DistanceToNextPump { get; set; }
- }// class Pump
- class TruckTour
- {
- static void Main(string[] args)
- {
- Queue<Pump> pumps = new Queue<Pump>();
- int n = int.Parse(Console.ReadLine());
- for (int i = 0; i < n; i++)
- {
- int[] input = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- int fuel = input[0];
- int distance = input[1];
- Pump pump = new Pump(i, fuel, distance);
- pumps.Enqueue(pump);
- }
- int countOfPump = 0;
- int currentStartIndex = -1;
- int currentFuel = 0;
- int noPumps = 0;
- while ((countOfPump < n) && (noPumps < 2 * n))
- {
- Pump pump = pumps.Dequeue();
- pumps.Enqueue(pump);
- noPumps++;
- currentFuel += pump.Fuel;
- if (currentFuel >= pump.DistanceToNextPump)
- {
- countOfPump++;
- currentFuel -= pump.DistanceToNextPump;
- if (currentStartIndex.Equals(-1))
- {
- currentStartIndex = pump.Num;
- }
- }
- else
- {
- countOfPump = 0;
- currentFuel = 0;
- currentStartIndex = -1;
- }
- }
- if (noPumps < 2 * n)
- {
- Console.WriteLine(currentStartIndex);
- }
- else
- {
- Console.WriteLine("No");
- }
- }
- }
- }
Advertisement
RAW Paste Data
Copied
Advertisement