General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
18469783 Contestant:
m.khooryani
681C - 23 MS C# Time limit exceeded on test 26 1000 ms 29220 KB 2016-06-14 20:42:59 2016-06-14 22:20:14
 
 
→ Source
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Codeforces
{
    class Program
    {
        static StreamReader reader;
        static StreamWriter writer;
        static Random rand = new Random(0);

        static void Main(string[] args)
        {
            //#if DEBUG
            reader = new StreamReader(Console.OpenStandardInput(32768), Encoding.ASCII, false, 32768);
            writer = new StreamWriter(Console.OpenStandardOutput(32768), Encoding.ASCII, 32768);
            //#else
            //            StreamReader streamReader = new StreamReader(Console.OpenStandardInput(32768), Encoding.ASCII, false, 32768);
            //            StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(32768), Encoding.ASCII, 32768);
            //#endif
            InputReader input = new InputReader(reader);

            int n = input.NextInt();
            List<string> commands = new List<string>();
            SortedList<int, MyInt> sl = new SortedList<int, MyInt>();
            for (int i = 0; i < n; i++)
            {
                string str = input.Next();
                if (str[0] == 'i')
                {
                    int x = input.NextInt();
                    commands.Add(str + " " + x);
                    if (!(sl.ContainsKey(x)))
                    {
                        sl.Add(x, new MyInt());
                    }
                    sl[x].data++;
                }
                else
                {
                    if (str[0] == 'r')
                    {
                        if (sl.Count == 0)
                        {
                            commands.Add("insert 0");
                            sl.Add(0, new MyInt());
                            sl[0].data++;
                        }
                        commands.Add(str);
                        sl.Values[0].data--;
                        if (sl.Values[0] .data== 0)
                        {
                            sl.RemoveAt(0);
                        }
                    }
                    else
                    {
                        int x = input.NextInt();
                        if (sl.Count == 0)
                        {
                            commands.Add("insert " + x);
                            sl.Add(x, new MyInt());
                            sl[x].data++;
                            commands.Add(str + " " + x);
                        }
                        else
                        {
                            if (sl.Keys[0] == x)
                            {
                                commands.Add(str + " " + x);
                            }
                            else
                            {
                                if (!sl.ContainsKey(x))
                                {
                                    while (!(sl.Count == 0 || sl.Keys[0] >= x))
                                    {
                                        sl.Values[0].data--;
                                        commands.Add("removeMin");
                                        if (sl.Values[0].data == 0)
                                        {
                                            sl.RemoveAt(0);
                                        }
                                    }
                                    commands.Add("insert " + x);
                                    if (!sl.ContainsKey(x))
                                    {
                                        sl.Add(x, new MyInt());
                                    }
                                    sl[x].data++;
                                    commands.Add(str + " " + x);
                                }
                                else
                                {
                                    while (!(sl.Count == 0 || sl.Keys[0] >= x))
                                    {
                                        sl.Values[0].data--;
                                        commands.Add("removeMin");
                                        if (sl.Values[0].data == 0)
                                        {
                                            sl.RemoveAt(0);
                                        }
                                    }
                                    commands.Add(str + " " + x);
                                }
                            }
                        }
                    }
                }
            }
            writer.WriteLine(commands.Count);
            foreach(string cmd in commands)
            {
                writer.WriteLine(cmd);
            }


#if DEBUG
                Console.BackgroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Black;
#endif
            writer.Flush();
            writer.Close();
            reader.Close();
        }
    }

    class MyInt
    {
        public int data;

    }

    class MyPair
    {
        public int x, y;

        public MyPair(int x, int y)
        {
            this.x = x;
            this.y = y;
        }
    }

    // this class is copy
    class InputReader
    {
        private char[] _inbuf;
        private int _lenbuf = 0, _ptrbuf = 0;
        private StreamReader _reader;

        public InputReader(StreamReader reader)
        {
            _reader = reader;
            _inbuf = new char[1024];
            _lenbuf = 0;
            _ptrbuf = 0;
        }

        private int ReadByte()
        {
            if (_lenbuf == -1)
                throw new Exception();
            if (_ptrbuf >= _lenbuf)
            {
                _ptrbuf = 0;
                try
                {
                    _lenbuf = _reader.Read(_inbuf, 0, 1024);
                }
                catch (IOException e)
                {
                    throw e;
                }
                if (_lenbuf <= 0)
                    return -1;
            }
            return _inbuf[_ptrbuf++];
        }

        private bool IsSpaceChar(int c)
        {
            return !(c >= 33 && c <= 126);
        }

        private int Skip()
        {
            int b;
            while ((b = ReadByte()) != -1 && IsSpaceChar(b)) ;
            return b;
        }

        public int NextInt()
        {
            return int.Parse(this.Next());
        }

        public int[] NextIntArray(int n)
        {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = NextInt();
            }
            return a;
        }

        public long NextLong()
        {
            return long.Parse(this.Next());
        }

        public string Next()
        {
            var b = Skip();
            var sb = new StringBuilder();
            while (!(IsSpaceChar(b)))
            {
                sb.Append((char)b);
                b = ReadByte();
            }
            return sb.ToString();
        }

        public double NextDouble()
        {
            return double.Parse(Next(), CultureInfo.InvariantCulture);
        }

        internal long[] NextLongArray(long n)
        {
            long[] a = new long[(int)n];
            for (int i = 0; i < a.Length; i++)
            {
                a[i] = NextLong();
            }
            return a;
        }

        internal double[] NextDoubleArray(int n)
        {
            double[] a = new double[n];
            for (int i = 0; i < a.Length; i++)
            {
                a[i] = NextDouble();
            }
            return a;
        }
    }
}
 
 
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details