Lang:G++
Edit12345678910111213141516171819202122232425262728293031#include <iostream>#include <algorithm>using namespace std;class Goods{public:int need;int value;Goods():need(0), value(0){}friend istream& operator>>(istream& is, Goods& goods);};istream& operator>>(istream& is, Goods& goods){is>>goods.need>>goods.value;return is;}int comp(const Goods& g1, const Goods& g2){if(g1.value*1.0/g1.need > g2.value*1.0/g2.need)return 1;elsereturn 0;}void fun(Goods* goods, int idx, int& total, int M, int& max){if(idx<0){if(total > max)max = total;