Pagini recente » Cod sursa (job #806061) | Cod sursa (job #1627277) | Cod sursa (job #563411) | Cod sursa (job #1280794) | Cod sursa (job #1875867)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int a[2][10001];
struct abc{
int greutate;
int profit;
}x[5001];
int main() {
int n, g;
fin >> n >> g;
for (int i = 1; i <= n; i++)
fin >> x[i].greutate >> x[i].profit;
for (int i = 1; i <= n; i++)
for (int j = 0; j <= g; j++)
if (j >= x[i].greutate)
a[i % 2][j] = max (a[(i - 1) % 2][j], a[(i - 1) % 2][j - x[i].greutate] + x[i].profit);
else
a[i % 2][j] = a[(i - 1) % 2][j];
fout << a[n % 2][g];
return 0;
}