Pagini recente » Cod sursa (job #1237434) | Cod sursa (job #2986775) | Cod sursa (job #89832) | Cod sursa (job #1512802) | Cod sursa (job #3285574)
// ConsoleApplication1.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <fstream>
#include <vector>
using namespace std;
ifstream cin("rucsac.in");
ofstream cout("rucsac.out");
int n, g;
struct ob {
int gr;
int p;
};
ob obj[50001];
int mat[10001][10001];
int main()
{
cin >> n >> g;
for (int i = 1;i <= n;i++)
{
cin >> obj[i].gr >> obj[i].p;
for (int j = obj[i].gr;j <= g;j++)
{
mat[i][j] = max(mat[i - 1][j], mat[i - 1][j - obj[i].gr] + obj[i].p);
}
}
cout << mat[n][g];
}