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 #include #include using namespace std; int calcBottlesToTakeOff(int row, int col) { int closerCol = (col <= row/2) ? col : (row - col); return (closerCol + 1) * (row - closerCol + 1); } int main() { int height; int neededBottlesNum; scanf("%d %d\n", &height, &neededBottlesNum); vector > wineYears; for (int i = 0; i < height; i++) { wineYears.push_back(vector()); for (int j = 0; j < i + 1; j++) { int nextYear; scanf("%d", &nextYear); wineYears[i].push_back(nextYear); } } int minYear = wineYears[0][0]; for (int i = 1; i < height; i++) { for (int j = 0; j < i + 1; j++) { int nextYear = wineYears[i][j]; if (nextYear < minYear && calcBottlesToTakeOff(i, j) <= neededBottlesNum) { minYear = nextYear; } } } printf("%d\n", minYear); return 0; }