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
48
49
50
51
52
#include <iostream>

using namespace std;
unsigned int mins[1000000];

int main()
{
    ios::sync_with_stdio(false);

    unsigned long long int bottlesCount;
    unsigned int height;
    unsigned int year;
    unsigned long long int maxGroup = 0;



    if (!scanf("%u %u", &height, &bottlesCount))
    {
        printf("ooops!\n");
    }

    for (unsigned int row = 1; row <= height; row++)
    {
        unsigned int diff = row;
        unsigned long long int group = 0;
        
        for (unsigned int bottle = 1; bottle <= row; bottle++)
        {
            if (!scanf("%u", &year))
            {
                printf("ooops!\n");
            }

            group += diff;
            diff -=2;

            if(year < mins[group] || mins[group] == 0) mins[group] = year;
            if(group > maxGroup) maxGroup = group;
        }
    }

    unsigned int result = 2020;
    //cout << "maxGroup: " << maxGroup << "\n";
    for(unsigned long long int i = bottlesCount; i >= 1; i--){
        //\\||||ihiohoihiohiodfjihjdjdjsidjmarlenkajestsupercout << "group: " << i << ", min: " << mins[i] << "\n";
        if(mins[i] != 0 && mins[i] < result) result = mins[i];
    }

    printf("%u\n", result);

    return 0;
}