Pagini recente » Cod sursa (job #724584) | Cod sursa (job #2806527) | Cod sursa (job #235708) | Cod sursa (job #2812916) | Cod sursa (job #1154055)
#include<stdio.h>
#include<algorithm>
using namespace std;
const int I_am_the_boss=21;//00000000;
int cost[1001],profit[1001],mat[2][5002];
int main()
{
int N,G;
for(int i=0;i<=5000;i++)
mat[0][i]=I_am_the_boss;
freopen("energii.in","r",stdin);
freopen("energii.out","w",stdout);
scanf("%d%d",&N,&G);
for(int i=1;i<=N;++i)
scanf("%d%d",&profit[i],&cost[i]);
int l=1;
for(int i=1;i<=N;++i,l=1-l){
for(int j=0;j<=G;j++){
if(profit[i]>=j)
mat[l][j]=min(mat[1-l][j],cost[i]);
else
mat[l][j]=min(I_am_the_boss,mat[1-l][j-profit[i]]+cost[i]);
}
}
if(mat[1-l][G]!=I_am_the_boss)
printf("%d",mat[1-l][G]);
else
printf("-1");
fclose(stdin);fclose(stdout);
return 0;
}