Pagini recente » Cod sursa (job #2691613) | Cod sursa (job #959276) | Cod sursa (job #139590) | Cod sursa (job #621351) | Cod sursa (job #2342133)
#include <fstream>
using namespace std;
ifstream fin("energii.in");
ofstream fout("energii.out");
int profit[100000],e[1002],c[1002];
int main()
{
int n,w;
fin>>n>>w;
int emax=0;
for(int i=0;i<n;i++)
{fin>>e[i]>>c[i]; emax=max(emax,e[i]);}
profit[0]=0;
for(int j=1;j<=w+emax;j++)
profit[j]=100000000;
for(int i=0;i<n;i++)
{
for(int j=w-1;j>=0;j--)
{
if(profit[j]!=100000000 && profit[j]+c[i]<profit[j+e[i]])
profit[j+e[i]]=profit[j]+c[i];
}
}
int minim=10000000000;
for(int i=w;i<=w+emax;i++)
{
minim=min(minim,profit[i]);
}
fout<<minim;
return 0;
}