Can somebody please tell me what is wrong with my code? I keep getting wa
typedef long long int lli;
int dp[101][501];
int main()
{
while(1)
{
lli budget, n;
cin >> budget >> n;
if(budget==0 && n==0)
break;
vector > cost;
lli temp1, temp2;
for(int i=0;i {
scanf("%lld %lld",&temp1, &temp2);
cost.push_back(make_pair(temp1, temp2));
}
sort(cost.begin(), cost.end());
for(int i=0;i<n;i++)
dp[i][0]=0;
for(int i=0;i<budget+1;i++)
{
if(cost[0].first<=i)
dp[0][i]=cost[0].second;
else
dp[0][i]=0;
}
for(int i=1;i<n;i++)
{
for(int j=0;j<budget+1;j++)
{
if(cost[i].first>j)
dp[i][j]=dp[i-1][j];
else
dp[i][j]=max(dp[i-1][j], cost[i].second+dp[i-1][j-cost[i].first]);
}
}
int j=budget;
int totalcost=0;
for(int i=n-1;i>=0;i--)
{
if(i==0 && dp[i][j]!=0)
{
if(cost[i].second!=0)
totalcost+=cost[i].first;
}
if(i>0 && dp[i][j]!=dp[i-1][j])
{
if(cost[i].second!=0)
{
totalcost+=cost[i].first;
j=j-cost[i].first;
}
}
}
cout << totalcost <<" "<<dp[n-1][budget] << endl;
}
}