Problem:
Score : 300 points

Problem Statement

There is an empty array.
The following N operations will be performed to insert integers into the array.
In the i-th operation (1≤i≤N), b_i copies of an integer a_i are inserted into the array.
Find the K-th smallest integer in the array after the N operations.
For example, the 4-th smallest integer in the array \{1,2,2,3,3,3\} is 3.

Constraints

1≤N≤10^5

1≤a_i,b_i≤10^5

1≤K≤b_1…+…b_n

All input values are integers.

Input

Input is given from Standard Input in the following format:

N K
a_1 b_1
:
a_N b_N

Output

Print the K-th smallest integer in the array after the N operations.

Sample Input 1

3 4
1 1
2 2
3 3

Sample Output 1

3

The resulting array is the same as the one in the problem statement.

Sample Input 2

10 500000
1 100000
1 100000
1 100000
1 100000
1 100000
100000 100000
100000 100000
100000 100000
100000 100000
100000 100000

Sample Output 2

1

Solution in C# (Mono 4.6.2.0) (judge verdict: Runtime Error)

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    public class Prog
    {
        const int MOD = 1000000007;
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Prog().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
        }

        public void Solve(ConsoleInput cin)
        {
            var n = cin.ReadInt;
            var k = cin.ReadInt;
            var a = new int[n];
            var b = new int[n];
            cin.ReadIntArrays(n, out a, out b);
            var dic = new Dictionary<int, long>();

            for (int i = 0; i < n; i++)
            {
                var at = a[i];
                var bt = b[i];
                if (dic.ContainsKey(at))
                {
                    dic[at] += bt;
                }
                else
                {
                    dic.Add(at, bt);
                }
            }

            var ans = 0;
            var sum = 0L;

            for (int i = 0; i < 100001; i++)
            {
                if(dic.ContainsKey(i))
                {
                    sum += dic[i];
                    if (k <= sum)
                    {
                        ans = i;
                        break;
                    }
                }
            }

            Console.WriteLine(ans);
        }

        class Modulo
        {
            private const int M = 1000000007;
            private readonly int[] m_facs;
            public int Mul(int a, int b)
            {
                return (int)(Math.BigMul(a, b) % M);
            }
            public Modulo(int n)
            {
                m_facs = new int[n + 1];
                m_facs[0] = 1;
                for (int i = 1; i <= n; ++i)
                {
                    m_facs[i] = Mul(m_facs[i - 1], i);
                }
            }
            public int Fac(int n)
            {
                return m_facs[n];
            }
            public int Pow(int a, int m)
            {
                switch (m)
                {
                    case 0:
                        return 1;
                    case 1:
                        return a;
                    default:
                        int p1 = Pow(a, m / 2);
                        int p2 = Mul(p1, p1);
                        return ((m % 2) == 0) ? p2 : Mul(p2, a);
                }
            }
            public int Div(int a, int b)
            {
                return Mul(a, Pow(b, M - 2));
            }
            public int Ncr(int n, int r)
            {
                if (n < r) { return 0; }
                if (n == r) { return 1; }
                int res = Fac(n);
                res = Div(res, Fac(r));
                res = Div(res, Fac(n - r));
                return res;
            }
        }
    }
    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        public void ReadIntArrays(long N, out int[] A, out int[] B) { A = new int[N]; B = new int[N]; for (long i = 0; i < N; ++i) { A[i] = ReadInt; B[i] = ReadInt; } }
    }
}