#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <bitset>
#include <vector>
#define MAXN 40000
using namespace std;
struct dish
{
string name;
long long s;
int p;
};
long long n, m;
long long s[MAXN];
int cd[MAXN];
int cdif[MAXN];
bool* dif[MAXN];
dish md[101];
void init()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
double t;
cin >> md[i].name >> md[i].p >> t;
md[i].s = (long long)(t*1000);
}
for (int i = 0; i < MAXN; i++)
dif[i] = (bool*) malloc(101);
for (int i = 0; i < MAXN; i++)
for (int j = 0; j < 101; j++)
dif[i][j] = false;
}
void initd()
{
s[0] = 0;
m = m * 1000;
}
void solve()
{
for (int i = 0; i < MAXN; i++) s[i] = 10000000000000000LL;
initd();
for (int i = 0; i < MAXN; i++)
{
for (int j = 1; j <= n; j++)
{
if (i + md[j].s < MAXN && md[j].p + s[i] < s[i + md[j].s]) // prove price
{
s[i + md[j].s] = md[j].p + s[i];
cdif[i + md[j].s] = cdif[i] + (dif[i][j] ? 0 : 1);
cd[i + md[j].s] = j;
dif[i][j] = true;
memcpy(dif[i + md[j].s],dif[i], 101);
}
if (i + md[j].s < MAXN && md[j].p + s[i] == s[i + md[j].s])
{
if (cdif[i] + (dif[i][j] ? 0 : 1) > cdif[i + md[j].s]) // prove count diff and diff
{
s[i + md[j].s] = md[j].p + s[i];
cdif[i + md[j].s] = cdif[i] + (dif[i][j] ? 0 : 1);
cd[i + md[j].s] = j;
dif[i][j] = true;
memcpy(dif[i + md[j].s],dif[i], 101);
}
}
}
}
}
void recoversolve()
{
int cnt[101]; for (int i = 0; i < 101; i++) cnt[i] = 0;
long long int pr = 1000000000000000LL;
int u = 0;
int cntdif = 0;
for (int i = m; i < MAXN; i++)
{
if (s[i] < pr)
{
pr = s[i];
cntdif = cdif[i];
u = i;
}
if (s[i] == pr && cdif[i] > cntdif)
{
pr = s[i];
cntdif = cdif[i];
u = i;
}
}
cout << pr << endl;
while (pr > 0)
{
cnt[cd[u]]++;
pr -= md[cd[u]].p;
u -= md[cd[u]].s;
}
for (int i = 1; i <= n; i++)
{
if (cnt[i] > 0)
{
cout << md[i].name << " " << cnt[i] << endl;
}
}
}
void end()
{
for (int i = 0; i < MAXN; i++)
free(dif[i]);
}
int main()
{
init();
solve();
recoversolve();
end();
return 0;
}