Cod sursa(job #2932394)
| Utilizator | Data | 2 noiembrie 2022 19:38:51 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 65 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.62 kb |
#include <fstream>
using namespace std;
int greu[10005], efort[10005];
int main()
{
ifstream in("rucsac.in");
ofstream out("rucsac.out");
int n, g, gr, ef, i, j, maxx=0;
in>>n>>g;
greu[0]=1;
for (i=1;i<=n;i++) {
in>>gr>>ef;
for (j=g;j>=0;j--) {
if (greu[j]==1) {
greu[j+gr]=1;
if (efort[j+gr]<ef+efort[j]) {
efort[j+gr]=ef+efort[j];
}
if (j+gr<=g) {
maxx=max(maxx, efort[j+gr]);
}
}
}
}
out<<maxx;
return 0;
}
