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
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <climits>
#include <memory.h>

using namespace std;

// globals, to work around the error in the compiler
long bottles = 0L;
long rrows   = 0L;

int main(int argc, char* argv[])
{
	long minYear  = 3000L;
	int  currYear = 0L;

	scanf("%ld %ld\n", &rrows, &bottles);

	long m1 = 1L;  // multipliers to count bottles needed to be take out
	long m2 = 1L;

	for (long currRow = 1L; currRow <= rrows; ++currRow)
	{
		m1 = 1L;
		m2 = currRow;

		if (m2 > bottles)
			break;

		while (m2 > 0L)
		{
			scanf("%ld", &currYear);

			if ((m1 * m2) <= bottles)
			{
				if (currYear < minYear)
					minYear = currYear;
			}
			--m2;
			++m1;
		}
	}

	printf("%ld", minYear);

	return 0;
}