Pagini recente » Cod sursa (job #3123912) | Profil xUnuOarecare | Cod sursa (job #1703825) | Cod sursa (job #974508) | Cod sursa (job #2731399)
#include <fstream>
#define nmax 10005
#define dmax 5005
using namespace std;
ifstream in("energii.in");
ofstream out("energii.out");
int g, w;
int put[nmax], cost[nmax], d[dmax];
int main()
{
in>>g>>w;
for(int i=1; i<=g; i++)
{
in>>put[i]>>cost[i];
s+=cost[i];
}
if(s<w)
out<<-1;
else
{
for(int i=1; i<=w; i++)
{
d[i] = 2000000000;
}
for(int i=1; i<=g; i++)
{
for(int j=w; j>=0; j--)
{
if(put[i]+j>w)
d[w] = min(cost[i]+d[j], d[w]);
else
d[j+put[i]] = min(d[j]+cost[i],d[j+put[i]]);
}
}
out<<d[w];
}
return 0;
}