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

int main(int argc, const char * argv[]) {
    
    int rows, bottles, current, min = 10000 ;
    
    std::cin >> rows;
    std::cin >> bottles;
    
    int* cost = new int[rows];
    cost[0] = 0;
   
    int row = 0;
    for(int i=0; i<=rows;i++)
    {
        for(int j=0;j<row;j++)
        {
            std::cin >> current;
            if(cost[j] <= bottles)
            {
                min = std::min(min, current);
            }
        }
        row++;
        for(int j=0;j<((row+1)/2); j++)
        {
            cost[j] = cost[j] + j + 1;
            cost[row - j - 1] = cost[j];
        }
    }
    std::cout << min;
    return 0;
}