Cod sursa(job #3237081)
Utilizator | Data | 4 iulie 2024 16:52:20 | |
---|---|---|---|
Problema | Problema rucsacului | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include <fstream>
#include <vector>
using namespace std;
ifstream cin("rucsac.in");
ofstream cout("rucsac.out");
int n,g;
vector<int> W,P,dp;
int maxi;
int main()
{
cin>>n>>g;
W.resize(n+1);
P.resize(n+1);
dp.resize(g+1);
for(int i=1;i<=n;i++)
cin>>W[i]>>P[i];
for(int i=1;i<=n;i++)
for(int j=g;j>=W[i];j--)
{
dp[j]=max(dp[j],dp[j-W[i]]+P[i]);
maxi=max(maxi,dp[j]);
}
cout<<maxi;
return 0;
}