Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ClubParty
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- var hall = new Dictionary<string, List<int>>();
- var line = Console.ReadLine().Split(' ' , StringSplitOptions.RemoveEmptyEntries).Reverse().ToList();
- int capacity = 0;
- for (int i = 0; i < line.Count; i++)
- {
- if (int.TryParse(line[i] , out int number) && hall.Count > 0)
- {
- capacity += number;
- if(capacity <= n)
- {
- var hallNumber = hall.Keys.First();
- hall[hallNumber].Add(int.Parse(line[i]));
- }
- else if (hall.Count > 0)
- {
- foreach (var (key, value) in hall)
- {
- if (value.Count > 0)
- {
- Console.Write($"{key} -> ");
- Console.Write(string.Join(", ", value));
- Console.WriteLine();
- hall.Remove(key);
- capacity = 0;
- break;
- }
- else
- {
- capacity -= number;
- }
- }
- if (hall.Count > 0 && number <= n)
- {
- var hallNumber = hall.Keys.First();
- hall[hallNumber].Add(int.Parse(line[i]));
- capacity += number;
- }
- }
- }
- else
- {
- if (!hall.ContainsKey(line[i]) && char.TryParse(line[i] , out char result))
- {
- if (char.IsLetter(result))
- {
- hall[line[i]] = new List<int>();
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement