Why I am getting run time error while it shown correct output

#include
using namespace std;
int main() {
int tc;//testcases
int i;
int j,k,t,d,n,totalcost;
int num[100];
cin>>tc;
for(i=0;i<tc;i++)
{
cin>>n;
cin>>k;
totalcost=0;
for(j=0;j<n;j++)
{
cin>>t;//time in minutes…
cin>>d;//costs per minutes
if(t<k)
{
totalcost=0+totalcost;
k=k-t;
}
else
{
if(k>0)
{
totalcost=((t-k)d)+totalcost;
k=k-t;
}
else
{
totalcost=t
d+totalcost;
}
}

}
num[i]=totalcost;

}
for(i=0;i<tc;i++)
{
cout<<num[i]<<endl;
}
return 0;
}

//