Beispiel #1
0
        static void Main(string[] args)
        {
            var reader = new TextReaderHelper(new StreamReader(Console.OpenStandardInput(), Encoding.ASCII, false, 1048576));
            var writer = new StreamWriter(Console.OpenStandardOutput(), Encoding.ASCII, 1048576);
            int n = reader.NextInt(), s = reader.NextInt();
            var B = new SortedDictionary <int, int>(new BuyComparer());
            var S = new SortedDictionary <int, int>();

            for (int i = 1; i <= n; i++)
            {
                SortedDictionary <int, int> Now;
                if (reader.NextString() == "B")
                {
                    Now = B;
                }
                else
                {
                    Now = S;
                }
                int p = reader.NextInt(), q;
                Now.TryGetValue(p, out q);
                Now[p] = q + reader.NextInt();
            }
            var Emtr  = S.GetEnumerator();
            var stack = new Stack <string>();

            for (int i = 1; i <= s && Emtr.MoveNext(); i++)
            {
                stack.Push(string.Format("S {0} {1}", Emtr.Current.Key, Emtr.Current.Value));
            }
            while (stack.Count > 0)
            {
                writer.WriteLine(stack.Pop());
            }
            Emtr = B.GetEnumerator();
            for (int i = 1; i <= s && Emtr.MoveNext(); i++)
            {
                writer.WriteLine("B {0} {1}", Emtr.Current.Key, Emtr.Current.Value);
            }
            writer.Flush();
            Pause();
        }