Pagini recente » Cod sursa (job #1063265) | Cod sursa (job #2006363) | Cod sursa (job #1999613) | Cod sursa (job #1977531) | Cod sursa (job #1324714)
#include <fstream>
#define INF 13000000
using namespace std;
int main()
{
ifstream in("energii.in");
ofstream out("energii.out");
long g, w, e, c, *costs;
in>>g>>w;
costs=new long[w+1];
for(long i=0; i<=w; ++i)
costs[i]=INF;
for(long i=0; i<g; ++i)
{
in>>e>>c;
for(long j=e+1; j<=w; ++j)
if(c+costs[j-e]<costs[j]) costs[j]=c+costs[j-e];
for(long j=0; j<=e&&j<=w; ++j)
if(costs[j]>c) costs[j]=c;
}
if(costs[w]!=INF) out<<costs[w]<<endl;
else out<<"-1"<<endl;
return 0;
}