Pagini recente » Cod sursa (job #831398) | Cod sursa (job #3236271) | Cod sursa (job #2742079) | Cod sursa (job #3221839) | Cod sursa (job #2615536)
#include <bits/stdc++.h>
using namespace std;
int dp[4000001];
int main()
{
ifstream cin("energii.in");
ofstream cout("energii.out");
int i,j,n,e,emax,c;
cin>>n>>emax;
for(i=1;i<=emax;++i)
dp[i]=99999999;
for(i=1;i<=n;++i){
cin>>e>>c;
for(j=emax-1;j>=1;--j){
if(e+j>emax){
if(c+dp[j]<dp[emax])
dp[emax]=c+dp[j];
}
else
if(c+dp[j]<dp[j+e])
dp[j+e]=c+dp[j];
}
if(c<dp[e])
dp[e]=c;
}
if(dp[emax]!=99999999)
cout<<dp[emax];
else
cout<<-1;
return 0;
}