Cod sursa(job #3285574)

Utilizator AlexMoto2006Motoasca Alexandru-Lucian AlexMoto2006 Data 13 martie 2025 10:41:42
Problema Problema rucsacului Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.57 kb
// 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];
}