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++14 (GCC 5.4.1) (judge verdict: Wrong Answer)




#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>

auto& in = std::cin;
auto& out = std::cout;

int32_t N,K;
int32_t count[1000000];
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);

	in >> N>>K;
	for (int32_t i = 0; i < N; ++i)
	{
		int v, n;
		in >> v >> n;
		count[v] += n;
	}
	int32_t sum = 0;
	for (int32_t i = 0; i < 1000000; ++i)
	{
		sum += count[i];
		if (sum >= K) {
			std::cout << i << std::endl; return 0;
		}
	}


	return 0;
}
#endif

#if 0
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>

auto& in = std::cin;
auto& out = std::cout;


const int MAX_E = 2000;
const int MAX_V = 1000;
const int64_t INF = 10000000000000000;
// 頂点fromから頂点toへのコストcostの辺
struct edge { int from, to; int64_t cost; };
edge es[MAX_E]; // 辺
int64_t d[MAX_V]; // 最短距離
int V, E; // Vは頂点数、Eは辺数
		  // s番目の頂点から各頂点への最短距離を求める
void shortest_path(int s) {
	for (int i = 0; i < V; i++) d[i] = INF;
	d[s] = 0;
	while (true) {
		bool update = false;
		for (int i = 0; i < E; i++) {
			edge e = es[i];
			if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}
		}
		if (!update) break;
	}
}
// trueなら負の閉路が存在する
bool find_negative_loop() {
	for (int i = 0; i < V; i++) d[i] = 0;
	for (int i = 0; i < V; i++) {
			for (int j = 0; j < E; j++) {
				edge e = es[j];
				if (d[e.to] > d[e.from] + e.cost) {
					d[e.to] = d[e.from] + e.cost;
					// n回目にも更新があるなら負の閉路が存在する
					if (i == V - 1) return true;
				}
			}
	}
	return false;
}

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);

	in >> V>>E;
	for (int32_t i = 0; i < E; ++i)
	{
		int a, b, c;
		in >> a >> b >> c; --a; --b; c = -c;
		es[i] = edge{ a,b,c };
	}
	if (find_negative_loop()) {
		std::cout << "inf\n"; return 0;
	}
	shortest_path(0);
	std::cout << -d[V - 1] << std::endl;
	return 0;
}
#endif