Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace _14.TruckTour
- {
- public class Program
- {
- public static void Main(string[] args)
- {
- int petrolStations = int.Parse(Console.ReadLine());
- Queue<string> data = new Queue<string>();
- for (int i = 0; i < petrolStations; i++)
- {
- string text = Console.ReadLine();
- data.Enqueue(text);
- }
- int stationNumber = 0;
- int total = 0;
- while (data.Any())
- {
- Queue<string> innerData = new Queue<string>();
- string start = data.Peek();
- int[] information = start.Split().Select(int.Parse).ToArray();
- int fuel = information[0];
- int distance = information[1];
- total += fuel;
- total -= distance;
- if (total > -1)
- {
- innerData.Enqueue(start);
- data.Dequeue();
- }
- else
- {
- innerData.Enqueue(start);
- data.Dequeue();
- for (int i = 0; i < innerData.Count; i++)
- {
- string newData = innerData.Dequeue();
- data.Enqueue(newData);
- }
- total = 0;
- stationNumber++;
- }
- }
- Console.WriteLine(stationNumber);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement