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 sum(int n)
{
    return n * (n + 1) / 2;
}

int main()
{
    int n, k, a;
    std::cin >> n >> k;
    int smallest = 3000;
    for (int row = 1; row < n + 1; row++)
    {
        const int totalRowSum = sum(row);
        for (int col = 0; col < row; col++)
        {
            std::cin >> a;

            const int rightNumbers = sum(row - col - 1);
            const int leftNumbers = sum(col);
            const int finalNumber = totalRowSum - rightNumbers - leftNumbers;

            if (finalNumber <= k && a < smallest)
            {
                smallest = a;
            }
        }
    }
    std::cout << smallest << std::endl;
}