Cod sursa(job #2895542)
| Utilizator | Data | 29 aprilie 2022 11:05:02 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include<bits/stdc++.h>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
long long n, g, ans, dp[100005];
int main()
{
fin >> n >> g;
for (long long i = 1; i <= n; i++) {
long long x, y;
fin >> x >> y;
for (long long j = g - x; j >= 0; j--)
dp[j + x] = max(dp[j + x], dp[j] + y);
}
for (long long i = 1; i <= g; i++)
ans = max(ans, dp[i]);
fout << ans;
}
