Pagini recente » Cod sursa (job #1136913) | Cod sursa (job #3226180) | Cod sursa (job #2461762) | Cod sursa (job #2522807) | Cod sursa (job #540695)
Cod sursa(job #540695)
#include<fstream>
#include<algorithm>
using namespace std;
struct gen
{
int p,c,e;
};
gen a[100];
int g,i,j,w,cost;
long cmp(const gen & a, const gen & b)
{
return a.e<b.e;
}
int main()
{
ifstream fin("energii.in");
ofstream fout("energii.out");
fin>>g;
fin>>w;
for(i=1;i<=g;i++)
{
fin>>a[i].p>>a[i].c;
a[i].e=a[i].p-(a[i].c-a[i].p);
}
sort(a+1,a+g+1,cmp);
for(i=g;i>=1 && w;i--)
{
cost+=a[i].c;
w-=a[i].p;
}
if(w>0)
fout<<-1;
else
fout<<cost;
}