Pagini recente » Cod sursa (job #2355754) | Cod sursa (job #952928) | Cod sursa (job #673525) | Cod sursa (job #3209436) | Cod sursa (job #586856)
Cod sursa(job #586856)
#include <fstream>
#include <algorithm>
using namespace std;
struct s_gen
{
int p,c;
};
int n,w,c_total;
s_gen gen[1000];
bool comp(s_gen a,s_gen b);
int main()
{
ifstream in("energii.in");
ofstream out("energii.out");
int i1;
//citire
in>>n>>w;
for(i1=0;i1<n;i1++)
{
in>>gen[i1].p;
in>>gen[i1].c;
}
sort(gen,gen+n,comp);
i1=0;
while(w>0)
{
w -= gen[i1].p;
c_total += gen[i1].c;
i1++;
}
out<<c_total;
in.close();
out.close();
return 0;
}
bool comp(s_gen a,s_gen b)
{
return ((double)a.p/(double)a.c > (double)b.p/(double)b.c);
}