You are on page 1of 1

#include <bits/stdc++.

h>
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define mod 1000000007
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define fast_io std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
typedef long long int ll;
using namespace std;
ll mx = 100000000000000;

ll t[3000],c[3000];
ll dp[3000][3000];

ll f(ll n,ll weight)


{

if(dp[n][weight]!=-1)
return dp[n][weight];
// cout<<n<<" "<<weight<<endl;
if(weight<=0)
return 0;
if(n==0)
return mx;

ll x = f(n-1,weight);

// cout<<"for "<<n-1<<" "<<weight<<" "<<x<<endl;


ll y = c[n-1]+f(n-1,weight-t[n-1]);
// dp[n-1][weight-t[n-1]]=y;
// cout<<"for "<<n-1<<" "<<weight-t[n-1]<<" "<<y<<endl;
if(x<0)
x=mx;
if(y<0)
y=mx;
dp[n][weight]=min(x,y);
return dp[n][weight];

int main()
{
int n;
cin>>n;
for (int i = 0; i < n; ++i)
{
cin>>t[i]>>c[i];
t[i]++;
}

loop(i,0,3000)loop(j,0,3000)dp[i][j]=-1;
ll ans = f(n,n);
cout<<ans<<endl;

return 0;
}

You might also like