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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	int n; cin >> n;
	int p; cin >> p;
	vector< vector<int> > W;
	vector< vector<int> > K(n+1);
	vector<int>A; A.push_back(0);
	W.push_back(A); 
	int star=2021;
	K[0].push_back(0);
	K[0].push_back(0);
	for(int i=1; i<=n; i++)
	{
		vector <int> G;
		K[i].assign(i+2, 0);
		G.push_back(0);
		for(int j=1; j<=i; j++)
		{
			int a; cin >> a;
			G.push_back(a);
		}
		G.push_back(0);
		W.push_back(G);
	}
	
	for(int i=1; i<=n; i++)
	{
		for(int j=i; j<=n; j++)
		{
			if( (K[j-1][i]+i) > p)
			{
				break;
			}
			else
			{
				K[j][i]=K[j-1][i]+i;
				star=min(star, W[j][i]);
			}
		}
	}
	cout << star <<endl;
}