Cod sursa(job #3290040)
| Utilizator | Data | 29 martie 2025 12:19:16 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
#include <fstream>
using namespace std;
ifstream cin("rucsac.in");
ofstream cout("rucsac.out");
int profitmax[10005];
int main()
{
int n, gmax, rez;
cin>>n>>gmax;
for(int i = 1; i <= n; ++i)
{
int greutate, profit;
cin>>greutate>>profit;
for(int g = gmax; g >= greutate; --g)
{
profitmax[g] = max(profitmax[g], profitmax[g-greutate] + profit);
rez = max(rez, profitmax[g]);
}
}
cout<<rez;
return 0;
}
