Pagini recente » Cod sursa (job #2740285) | Cod sursa (job #1857246) | Borderou de evaluare (job #1036206) | Cod sursa (job #2967966) | Cod sursa (job #1612069)
#include <fstream>
#include <vector>
using namespace std;
ifstream is("rucsac.in");
ofstream os("rucsac.out");
int n, m, answ;
int g, p;
int main()
{
is >> n >> m;
vector<int> r(m + 1, -1);
r[0] = 0;
for ( int i = 1; i <= n; ++i )
{
is >> g >> p;
for ( int j = min(answ, m - g); j >= 0; --j )
if ( r[j] != -1 && r[j] + p > r[j + g] )
{
r[j + g] = r[j] + p;
answ = max(answ, r[j + g]);
}
}
os << answ;
is.close();
os.close();
return 0;
}