Pagini recente » Cod sursa (job #861402) | Cod sursa (job #498335) | Cod sursa (job #2882701) | Cod sursa (job #2845236) | Cod sursa (job #540700)
Cod sursa(job #540700)
#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;
}