#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

ifstream input("Bai4_18.inp");
ofstream output("Bai4_18.out");
int n, m;
struct store
{
	int index;
	int weig;
	int val;
	bool take;
};
vector <store> st;

int main()
{
	st.push_back(store{ 0, 0 });
	input >> n >> m;
	int a, b, c;
	int capacity = 0;
	for (int i = 0; i < n; ++i)
	{
		input >> a >> b >> c;
		for (int j = 0; j < c; ++j)
		st.push_back(store{ i, a, b, false });
		capacity += c;
	}
	vector <vector <int> > arr(capacity + 1, vector <int>(m + 1));
	fill(arr[0].begin(), arr[0].end(), 0);
	for (int i = 1; i <= capacity; ++i)
	{
		for (int j = 0; j <= m; ++j)
		{
			arr[i][j] = arr[i - 1][j];
			if (j >= st[i].weig && arr[i - 1][j - st[i].weig] + st[i].val > arr[i - 1][j])
			{
				arr[i][j] = arr[i - 1][j - st[i].weig] + st[i].val;
			}
		}
	}
	int temp = arr[capacity][m];
	output << temp << '\n';
	int M = m;
	for (int i = capacity; i >= 1; --i)
	{
		if (temp != arr[i - 1][M])
		{
			st[i].take = true;
			temp -= st[i].val;
			M -= st[i].weig;
		}
	}
	st.push_back(store{ -1, 0, 0, 0 });
	int tempi = 1;
	for (int i = 0; i < n; ++i)
	{
		int res = 0;
		while (st[tempi].index == i)
		{
			if (st[tempi].take == true)
			{
				++res;
			}
			++tempi;
		}
		output << res << '\n';
	}
	input.close();
	output.close();
	return 0;
}