Pagini recente » Cod sursa (job #425670) | Cod sursa (job #2565744) | Cod sursa (job #679529) | Monitorul de evaluare | Cod sursa (job #1570666)
#include<cstdio>
using namespace std;
int G,W,v[10005],maxim,c,p;
int main()
{
freopen("energii.in","r",stdin);
freopen("energii.out","w",stdout);
scanf("%d",&G);
scanf("%d",&W);
for(int i=1;i<=10005;i++) v[i]=999999;
v[0]=0;
maxim=0;
for (int i=1;i<=G;i++)
{
scanf("%d%d",&p,&c);
for(int j=0;j<=W;j++)
{
if (v[j+p]==999999 || v[j+p]>(v[j]+c))
{
v[j+p]=v[j]+c;
if ((j+p)>maxim) maxim=j+p;
}
}
}
int i=W;
bool ok=0;
while (!ok && i<10005)
{
if (v[i]!=999999)
{
ok=1;
printf("%d\n",v[i]);
}
}
if (!ok) printf("-1\n");
return 0;
}