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
#include <sstream>
#include <iostream>
#include <vector>

using namespace std;

vector<int> temp;

int main()
{
    string line;
    getline(cin, line);
    istringstream f(line);
    string s;
    while (getline(f, s, ' ')) {
        temp.push_back(stoi(s));
    }
    vector<int> piramida[temp[0]];

    for(int i=0; i<temp[0]; i++){
        getline(cin, line);
        istringstream ff(line);
        while (getline(ff, s, ' ')) {
            piramida[i].push_back(stoi(s));
        }
    }

    bool finish = false;
    int suma = 0;
    int i=0;
    int rocznik =piramida[0][0];
    while(suma<temp[1]){
        suma += piramida[i].size();

        
        for(int k=0;k<piramida[i].size();k++){
            if(piramida[i][k] < rocznik){
                rocznik = piramida[i][k];
            }
        }
        i++;
    }

    cout << rocznik << "\n";

	return 0;
}