Pagini recente » Cod sursa (job #823670) | Cod sursa (job #636798) | Cod sursa (job #35085) | Cod sursa (job #2594427) | Cod sursa (job #1265792)
#include<fstream>
using namespace std;
int e[10001], c[10001];
int cost[15002];
//cost[j] = costul minim necesar pt. produce energia j
int main()
{
ifstream in("energii.in");
ofstream out("energii.out");
int g,w,i,j;
int emax=0;
in>>g>>w;
for(i=1;i<=g;i++)
{
in>>e[i]>>c[i];
if(e[i]>emax) emax = e[i];
}
for(j=1; j<=w+emax; j++)
cost[j] = 10002;
for(i=1;i<=g;i++)
{
for (j = w - 1; j >= 0; j--)
if (cost[j]!=10002 && cost[j] + c[i] < cost[j + e[i]])
cost[j+e[i]] = cost[j] + c[i];
}
int r = 10002;
for(i=w;i<=w+emax;i++)
if(cost[i]<r) r=cost[i];
out<<r;
return 0;
}