Cod sursa(job #3305019)
| Utilizator | Data | 29 iulie 2025 15:17:34 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int n, gmax, dp[10010]; ///dp[i] = profitu maxim pana la o greutate totala <= i
struct Iris {
int greutate, profit;
}v[5010];
int main()
{
fin >> n >> gmax;
for(int i=1; i<=n; i++) {
fin >> v[i].greutate >> v[i].profit;
for(int j=gmax; j>=v[i].greutate; j--) dp[j] = max(dp[j], dp[j - v[i].greutate] + v[i].profit);
}
fout << *max_element(dp+1, dp+gmax+1);
return 0;
}
