1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<bits/stdc++.h> 
using namespace std;

struct Point 
{ 
    int w, k; 
};


int suma(int n)
{
	int w = (n*n+n)/2;
	if(w > 0) return w;
	return 0;
}

int main()
{
	int n, k;
	scanf("%d", &n);
	scanf("%d", &k);

	Point tab[suma(n)];

	for (int i=0; i < n; ++i)
	{
		for (int j=0; j <= i; ++j)
		{
			int x;
			scanf("%d", &x);

			tab[suma(i)+j].w = x;

			tab[suma(i)+j].k = suma(i)-suma(j-1)-suma(i-j-1)+1;
		}
	}

    sort(tab, tab+suma(n), [](Point a, Point b) {return a.w < b.w;});


    for (int i = 0; i < suma(n); ++i)
    {
    	if(tab[i].k <= k)
    	{
    		printf("%d\n", tab[i].w);
    		break;
    	}
    }

    return 0;
}