Gaurav678's blog

By Gaurav678, history, 5 years ago, In English

on some large test cases I am getting runtime error . please help

Your text to link here... https://cses.fi/problemset/task/1158/

Your code here...
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,b;
    cin>>n>>b;
    vector<ll>v(n+1) , vv(n+1);
    for(ll i=1 ; i<=n ; i++)
    {
        cin>>v[i];
    }
    for(ll i=1 ; i<=n ; i++)
    {
        cin>>vv[i];
    }
    vector<vector<ll>>dp(n+1 , vector<ll>(b+1,0));
    for(ll i=1 ; i<=b ; i++)
    {
        for(ll j=1 ; j<=n ; j++)
        {
            dp[j][i]=dp[j-1][i];
            ll left = i-v[j];
            if(left>=0)
            {
                dp[j][i] = max(dp[j-1][left] + vv[j] , dp[j][i]);
            }
        }
    }
    cout<<dp[n][b]<<endl;
}

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it