Cod sursa(job #2891713)
| Utilizator | Data | 19 aprilie 2022 16:04:28 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.56 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("rucsac.in");
ofstream g("rucsac.out");
const int GMAX=10001;
const int oo=1000000000;
int n,G,w,p,profit[GMAX],profiMaxim;
int main()
{
f>>n>>G;
for(int gr=1;gr<=G;gr++)
profit[gr]=-oo;
for(int i=1;i<=n;i++)
{
f>>w>>p;
for(int newG=G,oldG=G-w;oldG>=0;newG--,oldG--)
profit[newG]=max(profit[newG],profit[oldG]+p);
}
for(int gr=1;gr<=G;gr++)
profiMaxim=max(profiMaxim,profit[gr]);
g<<profiMaxim<<'\n';
return 0;
}
