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:

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?

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;
        int 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--)
        int ans=0;
        for(int i=0;i<=w;i++)

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