Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _07._TruckTour
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- string[] pumpStations = new string[n];
- for (int i = 0; i < n; i++)
- {
- pumpStations[i] = Console.ReadLine();
- }
- Queue<string> pumps = new Queue<string>(pumpStations);
- for (int i = 0; i < n; i++)
- {
- bool isValid = true;
- int tank = 0;
- for (int j = 0; j < n; j++)
- {
- string station = pumps.Dequeue();
- int[] paramaters = station.Split().Select(int.Parse).ToArray();
- int fuel = paramaters[0];
- int distance = paramaters[1];
- tank += fuel;
- tank -= distance;
- if (tank < 0)
- {
- isValid = false;
- }
- pumps.Enqueue(station);
- }
- if (isValid)
- {
- Console.WriteLine(i);
- return;
- }
- pumps.Enqueue(pumps.Dequeue());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement