Pagini recente » Borderou de evaluare (job #2510175) | Cod sursa (job #2226605) | Cod sursa (job #1144075) | Cod sursa (job #2727565) | Cod sursa (job #3230099)
#include <fstream>
using namespace std;
ifstream in("rucsac.in");
ofstream out("rucsac.out");
int n, g, dp[2][20010], i, j;
bool ths, othr = 1;
pair<int, int> a;
int main()
{
in >> n >> g;
for (i = 1; i <= n; i++)
{
in >> a.first >> a.second;
for (j = 1; j <= g; j++)
{
dp[ths][j] = dp[othr][j];
if (a.first <= j)
dp[ths][j] = max(dp[ths][j], dp[othr][j - a.first] + a.second);
}
ths = 1 - ths;
othr = 1 - othr;
}
out << dp[1][g];
return 0;
}