Pagini recente » Monitorul de evaluare | Cod sursa (job #2114988) | Diferente pentru problema/treesmen intre reviziile 11 si 10 | Cod sursa (job #1231933) | Cod sursa (job #3330886)
#include <bits/stdc++.h>
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int main() {
int n, m;
fin >> n >> m;
vector<int> collumn1(m + 1, 0);
for (int i = 1; i <= n; i++) {
int w, p;
vector<int> collumn2(m + 1, 0);
fin >> w >> p;
collumn2[w] = max(collumn1[w], p);
for (int j = 0; j <= m; j++) {
collumn2[j] = max(collumn2[j], collumn1[j]);
if (j + w <= m)
collumn2[j + w] = max(collumn1[j + w], collumn1[j] + p);
}
collumn1.assign(collumn2.begin(), collumn2.end());
}
int ans = 0;
for (int i = 0; i <= m; i++)
ans = max(ans, collumn1[i]);
fout << ans;
}