Pagini recente » Cod sursa (job #2622072) | Cod sursa (job #1215818) | Cod sursa (job #1954191) | Cod sursa (job #2936471) | Cod sursa (job #2311047)
#include<fstream>
#include<algorithm>
using namespace std;
ifstream f("rucsac.in");
ofstream g("rucsac.out");
struct obiect{
float G,V,E;
};
int n,Gmax,i;
obiect o[5001];
float c;
int cmp(obiect a, obiect b){
return a.E>b.E;
}
int main()
{
f>>n>>Gmax;
for(i=1;i<=n;i++)
{
f>>o[i].G>>o[i].V;
o[i].E=o[i].V/o[i].G;
}
sort(o+1,o+n+1,cmp);
i=1;
if(o[i].G>Gmax)
c=0;
else
while(i<=n&&Gmax>0)
{
if(Gmax-o[i].G>=0)
c=c+o[i].V;
else
c=c+Gmax*o[i].V/o[i].G;
Gmax=Gmax-o[i].G;
i++;}
g<<c;
return 0;
}