Problem x - Tower

given test cases are passing but some test cases are failing when I am submitting

code:
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long

vector<vector >v;
vector<vector >dp;

bool compare(vector&a,vector&b){
ll w1 = a[0],s1=a[1],w2=b[0],s2=b[1];
return w1+s1 >= w2+s2;
}
void solve(){
ll n;cin>>n;
v.resize(n,vector(3));
dp.resize(n,vector(10001));
for(ll i=0;i<n;i++){
cin>>v[i][0]>>v[i][1]>>v[i][2];
}
sort(v.begin(),v.end(),compare);
for(ll i=0;i<=v[0][1];i++){
dp[0][i]=v[0][2];
}
for(ll i=1;i<n;i++){
for(ll j=0;j<=10001;j++){
dp[i][j] = dp[i-1][j];
if(j<=v[i][1]){
dp[i][j] = max(dp[i-1][j],v[i][2]+(j+v[i][0]<=10 ? (dp[i-1][j+v[i][0]]):0));
}
}
}
cout <<dp[n-1][0]<<"\n";

}

int main(){
// cin.tie(0);
// cout.tie(0);
// cin.sync_with_stdio(0);
// cout.sync_with_stdio(0);

cout.precision(10);
int t=1;//cin>>t;
while(t--){
    solve();
}
return 0;

}

Hello Shubham, here in your code you are missing vector , you forgot at many places during the definition of v, dp and while resizing them. And we need to make w1+s1 > w2+s2 here equal to sign is creating the problem. So just remove the equal to sign and also replace the value from 10 to 10000 at the place where you have written j+v[i][0] <= 10
So pls have a look at this


This is your code with some little bit modification.
I hope it is clear to you. In case it is clear to you pls mark it as resolve and provide the rating as well as feedback so that we can improve ourselves.
In case there is still some confusion pls let me know, I will surely try to help you out.
Thanks :slight_smile:
Happy Coding !!

You can ask if you feel any problem in this

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.