SHARE
TWEET
Untitled
a guest
Jan 29th, 2018
58
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _6_Truck_Tour
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- var queue = new Queue<int[]>();
- for (int i = 0; i < n; i++)
- {
- var pump = Console.ReadLine().Split().Select(int.Parse).ToArray();
- queue.Enqueue(pump);
- }
- for (int currentStart = 0; currentStart < n - 1; currentStart++)
- {
- int fuel = 0;
- bool isSolution = true;
- for (int pumpsPassed = 0; pumpsPassed < n; pumpsPassed++)
- {
- var currentPump = queue.Dequeue();
- int pumpFuel = currentPump[0];
- int nextPupmDistance = currentPump[1];
- queue.Enqueue(currentPump);
- fuel += pumpFuel - nextPupmDistance;
- if (fuel<0)
- {
- currentStart += pumpsPassed;
- isSolution = false;
- break;
- }
- }
- if (isSolution)
- {
- Console.WriteLine(currentStart);
- break;
- }
- }
- }
- }
- }
RAW Paste Data

