Pagini recente » Cod sursa (job #3004755) | Cod sursa (job #949727) | Cod sursa (job #554452) | Cod sursa (job #2944498) | Cod sursa (job #1808837)
#include <stdio.h>
#define INF 10000014
using namespace std;
int n,w,c[10000],e[10000],cost[10000];
int main()
{
freopen("energii.in", "r", stdin);
freopen("energii.out", "w", stdout);
scanf("%d%d", &n, &w);
for(int i=1;i<=n;i++)
scanf("%d%d", &e[i], &c[i]);
for(int j=1;j<=w;j++)
cost[j]=INF;
cost[0]=0;
for(int i=1;i<=n;i++)
for(int j=w-1;j>=0;j--)
{
if(j+e[i]>=w)
{
if(cost[j]+c[i]<cost[w])
cost[w]=cost[j]+c[i];
}
else
{
if(cost[j]+c[i]<cost[j+e[i]])
cost[j+e[i]]=cost[j]+c[i];
}
}
if(cost[w]==10001) printf("-1");
else printf("%d", cost[w]);
return 0;
}