Pagini recente » Cod sursa (job #1217041) | Cod sursa (job #1348127) | Cod sursa (job #2372930) | Cod sursa (job #1675886) | Cod sursa (job #540698)
Cod sursa(job #540698)
#include<fstream>
#include<algorithm>
using namespace std;
struct gen
{
int p,c,e;
};
gen a[1001];
long g,i,j,w,cost;
int 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;
}