Solução: Problema do colecionador de moedas (Paulo Cesar)
From AdonaiMedrado.Pro.Br
Revision as of 12:35, 20 May 2009 by 200.17.147.2 (Talk) (New page: <code lang="C"> #include<iostream> #include<vector> #include<algorithm> using namespace std; class Market { public: Market(); int find_max_seals(); private: vector<int> _seals; i...)
#include<iostream>
- include<vector>
- include<algorithm>
using namespace std;
class Market { public:
Market(); int find_max_seals();
private:
vector<int> _seals; int _money;
};
Market:: Market() {
_money = 0;
int size; cin >> size; for(int cont = 0; cont < size; cont++) { int value; cin >> value; _seals.push_back(value); }
cin >> size; for(int cont = 0; cont < size; cont++) { int name; cin >> name; _money += _seals[name]; }
}
int Market:: find_max_seals() {
sort(_seals.begin(),_seals.end()); int value = 0, quant = 0; while(value <= _money) { value+=_seals[quant]; if(value <= _money) quant++; } return quant;
}
int main() {
Market market = Market(); cout << market.find_max_seals() << endl; return 0;
} code>