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

int main()
{
    int n, k, year, bottleCover;
    std::cin >> n >> k;

    std::vector<std::vector<int>> wines(static_cast<unsigned long>(n));
    for (int y = 1; y <= n; y++)
    {
        wines[y - 1] = std::vector<int>(static_cast<unsigned long>(y));
        for (int x = 0; x < y; x++)
        {
            std::cin >> year;
            wines[y - 1][x] = year;
        }
    }

    int wineForKing = 2019;
    for (int y = 1; y <= n; y++)
    {
        for (int i = 1; i <= n - y + 1; i++)
        {
            year = wines[(y - 1) + (i - 1)][y - 1];
            bottleCover = (i * y) - 1;
            if (bottleCover < k && year < wineForKing)
            {
                wineForKing = year;
            }
        }
    }
    std::cout << wineForKing << std::endl;
}