Code giving WA on c++(gcc 4.8.1) but getting accepted on c++(gcc 4.3.2)?

Here is the problem that I am attempting: http://www.codechef.com/problems/PPTEST

A simple knapsack problem solved using DP.

Here is the code that is getting accepted when I choose C++(gcc 4.3.2) as my language but giving WA for C++(gcc 4.8.1). Can somebody help me figure it out what could it be because of?

#include<cstdio>
#include<iostream>
 
using namespace std;
 
#define MAXN 100
int c[MAXN],p[MAXN],t[MAXN],dp[MAXN+1]={0};
 
int max(int a,int b)
{
    if(a>b)return a;
    else return b;
}
 
int main()
{
    int te;
    scanf("%d",&te);
    while(te--)
    {
        int n,w;
        scanf("%d%d",&n,&w);
        for(int i=0;i<=w;i++)dp[i]=0;
        for(int i=0;i<n;i++)scanf("%d%d%d",&c[i],&p[i],&t[i]);
        for(int i=0;i<n;i++)c[i]*=p[i];
        for(int i=0;i<n;i++)
            for(int j=w;j>=0;j--)
                dp[t[i]+j]=max(dp[j]+c[i],dp[t[i]+j]);
        int ans=0;
        for(int i=0;i<=w;i++)
            ans=max(ans,dp[i]);
        printf("%d\n",ans);
    }
}

you have problems in setting max size of dp array. Note that t[i] + j can go greater than MAX (100 in your case) that will make problems