Cod sursa(job #2891712)
| Utilizator | Data | 19 aprilie 2022 16:02:32 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 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]);
return 0;
}
