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

const int MAXN = 2000;
int n, k, bottles_cnt;
int bottles[MAXN*(MAXN+1)/2];

int best_from_diag(int startrow, int bottlid)
{
    int row = startrow;
    int best_bottle = 99999;
    int bottles_over = row + 1;
    while (row < n && bottles_over <= k){
        best_bottle = std::min(best_bottle, bottles[bottlid]);
        row += 1;
        bottlid += row + 1;
        bottles_over += startrow + 1;
    }
    return best_bottle;
}

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin >> n >> k;
    bottles_cnt = n*(n+1)/2;
    for(int i=0; i < bottles_cnt; ++i)
    {
        std::cin >> bottles[i];
    }
    int best_bottle = 99999;
    int bottlid = 0;
    for (int i=0; i<=n; ++i){
        bottlid += i;
        best_bottle = std::min(best_bottle, best_from_diag(i, bottlid));
    }
    std::cout << best_bottle << std::endl;
}