Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Text;
- public class Program
- {
- public static void Main()
- {
- int maxCapacity = int.Parse(Console.ReadLine());
- int copyOfMax = maxCapacity;
- Queue<string> halls = new Queue<string>();
- Queue<int> people = new Queue<int>();
- string[]input =Console.ReadLine().Split();
- for (int i=input.Length-1; i>=0; i--)
- {
- string currItem = input[i];
- if(char.IsLetter(currItem[0]))
- {
- halls.Enqueue(currItem);
- }
- else
- {
- if(halls.Count==0)
- {
- continue;
- }
- else
- {
- int currPeople = int.Parse(currItem);
- if(maxCapacity-currPeople>=0)
- {
- maxCapacity-=currPeople;
- people.Enqueue(currPeople);
- }
- else
- {
- maxCapacity = copyOfMax;
- Console.WriteLine("{0} -> {1}",halls.Dequeue(),string.Join(", ",people));
- people.Clear();
- i++;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement