#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;
ifstream f("lapte.in");
ofstream g("lapte.out");
typedef struct Compare
{
bool operator() (const pair<pair<int,int>, int> a,const pair<pair<int,int> ,int> b)
{
//if(a.first.first*b.first.second == a.first.second*b.first.first)
// return a.first.first < b.first.first;
//return a.first.first*b.first.second < a.first.second*b.first.first;
return a.first.first-a.first.second < b.first.first-b.first.second;
}
} ICompare;
#define MaxN 110
#define mid ((li+ls)>>1)
int N,L,Sol;
int SolB[MaxN],SolC[MaxN];
int B[MaxN],C[MaxN];
vector<pair<pair<int,int> , int> > A;
void citire(void)
{
int a,b;
f >> N >> L;
for(int i=1;i<=N;i++)
{
f >> a >> b;
A.push_back(make_pair(make_pair(a,b),i-1));
}
}
inline int isOk(int val)
{
for(int i=0;i<=N;i++)
B[i] = C[i] = 0;
int sum = 0;
for(int i=0;i<N && sum < L;i++)
B[i] = min(val/A[i].first.first,L-sum),
sum += B[i];
if(sum < L)
return 0;
sum = 0;
for(int i=N-1;i>=0;i--)
C[i] = min(val/A[i].first.second,L-sum),
sum += C[i];
if(sum < L)
return 0;
for(int i=0;i<N;i++)
if(A[i].first.first*B[i] + A[i].first.second*C[i] > val)
return 0;
return 1;
}
inline void copySol(void)
{
for(int i=0;i<N;i++)
SolC[A[i].second] = C[i],
SolB[A[i].second] = B[i];
}
inline int cautBin(int li,int ls)
{
if(li > ls)
return li;
if(isOk(mid))
{
copySol();
return cautBin(li,mid-1);
}
else
return cautBin(mid+1,ls);
}
void Rezolvare(void)
{
sort(A.begin(),A.end(),ICompare());
Sol = cautBin(1,100000);
}
int main()
{
citire();
Rezolvare();
g << Sol << "\n";
for(int i=0;i<N;i++)
g << SolB[i] << " " << SolC[i] << "\n";
}