#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class nwrule
{
int a[10][10],s,d,tcost,min,x,y,m,z;
public:
void getdata();
void result();
};
void nwrule::getdata()
{
cout<<"Enter the no. of souces";
cin>>s;
cout<<"Enter the no. of destinations";
cin>>d;
cout<<"Enter the cost of transportation from source to dest.";
for(int i=1;i<=s;i++)
{
for(int j=1;j<=d;j++)
{
cin>>a[i][j];
}
}
cout<<"Enter no. of sources available";
for(i=1;i<=s;i++)
{
cin>>a[i][d+1];
}
cout<<"Enter no. of sources available";
for(int j=1;j<=d;j++)
{
cin>>a[s+1][j];
}
a[s+1][d+1]=0;
}
void nwrule::result()
{
cout<<"Initial Basis"<<endl;
for(int i=1;i<=s+1;i++)
{
for(int j=1;j<=d+1;j++)
{
cout<<setw(3)<<a[i][j];
}
cout<<endl;
}
tcost=0;
p:
min=a[1][1];
cout<<"\n"<<min;
for(i=1;i<=s;i++)
{
for(int j=1;j<=d ;j++)
{
if(min>=a[i][j])
{
min=a[i][j];
x=i;
y=j;
}
}
}
cout<<"\n i:"<<x;
cout<<"\n j:"<<y;
cout<<"\n min:"<<min;
i=1;
int j=1;
if(a[x][d+1]>=a[s+1][y])
{
tcost+=(a[s+1][y]*min);
a[x][d+1]-=a[s+1][y];
for(i=1;i<=s;i++)
a[i][y]=1000;
}
else
{
tcost+=(a[x][d+1]*min);
a[s+1][y]-=a[x][d+1];
for(j=1;j<=d;j++)
a[x][j]=1000;
}
for(i=1;i<=s;i++)
{
for(j=1;j<=d;j++)
{
if(a[i][j]!=1000)
goto p;
}
}
cout<<"\n total cost:"<<tcost<<endl;
}
void main()
{
clrscr();
nwrule n;
n.getdata();
n.result();
getch();
}