Cod sursa(job #3373512)
| Utilizator | Data | 7 noiembrie 2026 10:57:05 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.43 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("rucsac.out");
ofstream fout("rucsac.in");
int main() {
int n, W;
fin >> n >> W;
vector<long long> dp(W + 1, 0);
for (int i = 0; i < n; ++i) {
int w;
long long p;
fin >> w >> p;
for (int c = W; c >= w; --c) {
dp[c] = max(dp[c], dp[c - w] + p);
}
}
fout << dp[W] << '\n';
return 0;
}