daily pastebin goal
41%
SHARE
TWEET

Untitled

a guest Jan 29th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _6_Truck_Tour
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int n = int.Parse(Console.ReadLine());
  12.  
  13.             var queue = new Queue<int[]>();
  14.  
  15.             for (int i = 0; i < n; i++)
  16.             {
  17.                 var pump = Console.ReadLine().Split().Select(int.Parse).ToArray();
  18.  
  19.                 queue.Enqueue(pump);
  20.             }
  21.  
  22.             for (int currentStart = 0; currentStart < n - 1; currentStart++)
  23.             {
  24.                 int fuel = 0;
  25.                 bool isSolution = true;
  26.                 for (int pumpsPassed = 0; pumpsPassed < n; pumpsPassed++)
  27.                 {
  28.                     var currentPump = queue.Dequeue();
  29.                     int pumpFuel = currentPump[0];
  30.                     int nextPupmDistance = currentPump[1];
  31.                     queue.Enqueue(currentPump);
  32.  
  33.                     fuel += pumpFuel - nextPupmDistance;
  34.                     if (fuel<0)
  35.                     {
  36.                         currentStart += pumpsPassed;
  37.                         isSolution = false;
  38.                         break;
  39.                     }
  40.                 }
  41.                 if (isSolution)
  42.                 {
  43.                     Console.WriteLine(currentStart);
  44.                     break;
  45.                 }
  46.             }
  47.         }
  48.     }
  49. }
RAW Paste Data
Pastebin PRO WINTER Special!
Get 40% OFF Pastebin PRO accounts!
Top