Pagini recente » Cod sursa (job #1352013) | Cod sursa (job #3224627) | Cod sursa (job #2413762) | Cod sursa (job #2300201) | Cod sursa (job #705281)
Cod sursa(job #705281)
#include<stdio.h>
#include<algorithm>
using namespace std;
int cost,E[100000],C[100000],ok,s,i,W,G,costmin;
int main()
{
freopen("energii.in","r",stdin);
freopen("energii.out","w",stdout);
scanf("%d",&G);
scanf("%d",&W);
for(i=1;i<=G;i++)
{
scanf("%d",&E[i]);
s=s+E[i];
scanf("%d",&C[i]);
}
for(i=1;i<=G;i++)
if(E[i]>=W)
costmin=C[i];
if(s<W)
printf("-1");
else
{
do
{
ok=1;
for(i=1;i<G;i++)
if(C[i]>C[i+1]&&E[i]<E[i+1])
{swap(C[i],C[i+1]);
swap(E[i],E[i+1]);ok=0;
}
}while(ok==0);
while(cost<=W&&i<=G)
{
cost+=C[i];
i++;
}
if(cost<W&&i<G)
{cost+=C[++i];
}
if(cost<=costmin)
printf("%d",cost);
else
printf("%d",costmin);
}
return 0;
}