Pagini recente » Cod sursa (job #626296) | Cod sursa (job #1066264) | Cod sursa (job #533662) | Cod sursa (job #2998604) | Cod sursa (job #2771813)
#include <iostream>
#include <algorithm>
#include <vector>
typedef struct obiect
{
int index;
float pret;
float greutate;
bool operator<(const obiect& other) const
{
return ((float)pret / (float)greutate) > ((float)other.pret / (float)other.greutate);
}
};
obiect v[1001];
float gMax, gCurent, s;
uint32_t i, n;
int main()
{
std::cin >> n >> gMax;
for (uint32_t i = 0; i < n; i++)
{
v[i].index = i+1;
std::cin >> v[i].greutate >> v[i].pret;
}
std::sort(v + 0, v + n);
while ((gCurent<=gMax) && (i < n))
{
if (v[i].greutate + gCurent <= gMax)
{
gCurent += v[i].greutate;
s += v[i].pret;
}
else
{
float f = ((float)(gMax) - (float)gCurent) / (float)v[i].greutate;
gCurent += v[i].greutate * f;
s += v[i].pret * f;
}
i++;
}
std::cout << s << '\n';
return 0;
}