Cod sursa(job #3358534)
| Utilizator | Data | 17 iunie 2026 14:17:16 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.42 kb |
#include <bits/stdc++.h>
using namespace std;
int dp[10005];
ifstream in("rj.in");
ofstream out("rj.out");
int main()
{
ios::sync_with_stdio(false);
in.tie(nullptr);
int n,G;
in>>n>>G;
for(int i=1;i<=n;i++)
{
int gp,p;
in>>gp>>p;
for(int g=G;g>=gp;g--)
{
dp[g]=max(dp[g],dp[g-gp]+p);
}
}
out<<dp[G];
return 0;
}
