Pagini recente » Cod sursa (job #2688965) | Cod sursa (job #1113806) | Cod sursa (job #804102) | Cod sursa (job #2480351) | Cod sursa (job #1457629)
#include <fstream>
#include <vector>
#include <utility>
using namespace std;
int rezolva(const vector<pair<int, int> >& obiecte, const int max_w){
vector<int> max_p_pe_w(max_w+1, 0);
for(const auto cur : obiecte){
for(int i = max_w-cur.first; i >= 0; --i){
max_p_pe_w[i+cur.first] = max(max_p_pe_w[i+cur.first],
max_p_pe_w[i] + cur.second); } }
return max_p_pe_w[max_w]; }
int main(){
ifstream f("rucsac.in");
ofstream g("rucsac.out");
int n, max_w;
f >> n >> max_w;
vector<pair<int, int> > obiecte(n);
for(auto& x : obiecte){
f >> x.first >> x.second; }
g << rezolva(obiecte, max_w);
return 0; }