Pagini recente » Cod sursa (job #1953878) | Cod sursa (job #325893) | Cod sursa (job #507792) | Cod sursa (job #2642083) | Cod sursa (job #1128241)
#include <fstream>
#define DEBUG 0
#if DEBUG
#include <iostream>
#include <iomanip>
#endif
using namespace std;
int a[10001];
int main()
{
ifstream in("rucsac.in");
ofstream out("rucsac.out");
int n, total;
in >> n >> total;
int g, p;
for (int i=0; i<n; ++i)
{
in >> g >> p;
for (int j=total; j>g; --j)
{
if (a[j-g]+p>a[j])
{
a[j] = a[j-g]+p;
}
}
if (a[g]<p) a[g] = p;
#if DEBUG
for (int j=1; j<=total; ++j)
{
cout << setw(3) << j << " ";
}
cout << " #" << g << " " << p << "\n";
for (int j=1; j<=total; ++j)
{
cout << setw(3) << a[j] << " ";
}
cout << "\n\n";
#endif
}
#if DEBUG
cout << a[total] << "\n";
#endif
out << a[total];
}