Help me in solving MAXCOMP problem plz give me dp approach better than this code

My issue

plz give me approach …

My code

#include<bits/stdc++.h>
using namespace std;
int dp[50];
void solve(){
    int s[2010][50];
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s[i][0]>>s[i][1]>>s[i][2];
    }
    dp[0]=0;
    for(int i=1;i<=48;i++){
        int val=dp[i-1];
        for(int j=0;j<n;j++){
            if(s[j][1]==i){
                val=max(val,s[j][2]+dp[s[j][0]]);
            }
        }
        dp[i]=val;
    }
    cout<<dp[48]<<"\n";
}
int main(){
    int t;
    cin>>t;
    while(t--){
        solve();
    }
}

Problem Link: MAXCOMP Problem - CodeChef