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

using namespace std;

int amountOfBottlesWithNAtBottom(int n)
{
    return n*(n + 1)/2;
}

int howManyBottlesAbove(int row, int column)
{
    return amountOfBottlesWithNAtBottom(row) - amountOfBottlesWithNAtBottom(column - 1) -
        amountOfBottlesWithNAtBottom(row - column);
}

int main() {
    ios_base::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    int theOldestOne = 2020;
    int yearbook = 0;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 0; j < i; j++) {
            cin >> yearbook;
            if (howManyBottlesAbove(i, j + 1) <= k and yearbook < theOldestOne)
                theOldestOne = yearbook;
        }
    }
    cout<<theOldestOne;

    return 0;
}