Cod sursa(job #3285589)

Utilizator AlexMoto2006Motoasca Alexandru-Lucian AlexMoto2006 Data 13 martie 2025 11:01:41
Problema Problema rucsacului Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.47 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;

int gr, p;

int mat[10001];

int main()
{
	cin >> n >> g;
	for (int i = 1;i <= n;i++)
	{
		cin >> gr >> p;
		for (int j = g;j >= gr;j--)
		{
			mat[j] = max(mat[j], mat[j - gr] + p);	
		}
	}
	cout << mat[g];
}