#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
struct Bean {
int weight;
int value;
double value_weight_ratio;
};
int beanBag(int capacity, vector<Bean>& beans) {
for (auto bean : beans) {
bean.value_weight_ratio = (double)bean.value / bean.weight;
}
sort(beans.begin(), beans.end(), [](const Bean& a, const Bean& b) {
return a.value_weight_ratio > b.value_weight_ratio;
});
int totalValue = 0;
for (auto bean : beans) {
if (capacity >= bean.weight) {
totalValue += bean.value;
capacity -= bean.weight;
}
}
return totalValue;
}
int main() {
int capacity = 20;
vector<Bean> beans = {{5, 10}, {10, 20}, {15, 30}, {8, 15}, {4, 7}};
int maxTotalValue = beanBag(capacity, beans);
cout << "总价值为: " << maxTotalValue << endl;
return 0;
}