Pagini recente » Cod sursa (job #1906989) | Cod sursa (job #1473284) | Cod sursa (job #438319) | Cod sursa (job #755473) | Cod sursa (job #1449789)
#include<cstdio>
struct generator{int e, c;};
generator v[1001];
int cost[15001];
int main(){
int i,n,w,g,j,max;
freopen("energii.in","r",stdin);
freopen("energii.out","w",stdout);
scanf("%d%d",&g,&w);
max=0;
for(i=1;i<=g;i++){
scanf("%d %d",&v[i].e,&v[i].c);
if(v[i].e>max)
max=v[i].e;
}
n=w+max;
for(i=1;i<=g;i++){
for(j=n;j>=1;j--)
if(cost[j]!=0)
if(j+v[i].e<=n)
if(cost[j+v[i].e]==0)
cost[j+v[i].e]=cost[j]+v[i].c;
else
if(cost[j]+v[i].c<cost[j+v[i].e])
cost[j+v[i].e]=cost[j]+v[i].c;
if(cost[v[i].e]==0)
cost[v[i].e]=v[i].c;
else
if(cost[v[i].e]>v[i].c)
cost[v[i].e]=v[i].c;
}
i=w;
while(cost[i]==0&&i<=n)
i++;
if(i==n+1)
printf("-1");
else
printf("%d",cost[i]);
return 0;
}