Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Stacks
- {
- class Program
- {
- static void Main(string[] args)
- {
- long countOfPumps = long.Parse(Console.ReadLine());
- Queue<long> pumps = new Queue<long>();
- for (int i = 0; i < countOfPumps; i++)
- {
- var data = Console.ReadLine()
- .Split()
- .Select(long.Parse)
- .ToArray();
- long num1 = data[0];
- long num2 = data[1];
- pumps.Enqueue(num1);
- pumps.Enqueue(num2);
- }
- long leftFuel = 0;
- int index = 0;
- int counter = 0;
- int mainCounter = 0;
- while (true)
- {
- var liters = pumps.Dequeue();
- var distance = pumps.Dequeue();
- if (liters + leftFuel >= distance)
- {
- leftFuel = leftFuel + liters - distance;
- counter++;
- }
- else if (liters + leftFuel < distance)
- {
- index = mainCounter + 1;
- counter = 0;
- }
- pumps.Enqueue(liters);
- pumps.Enqueue(distance);
- if (counter >= countOfPumps)
- {
- Console.WriteLine(index);
- return;
- }
- mainCounter++;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement