Pagini recente » Cod sursa (job #3146634) | Cod sursa (job #1426474) | Cod sursa (job #2513704) | Cod sursa (job #211573) | Cod sursa (job #2478212)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("cmlsc.in");
ofstream fout ("cmlsc.out");
const int N = 5005, M = 10005;
int w[N], p[N], d[2][M];
int main()
{
ios::sync_with_stdio(false);
fin.tie(0);
int n, m;
fin >> n >> m;
for(int i = 1; i <= n; ++i) fin >> w[i] >> p[i];
int phase = 1;
for(int i = 1; i <= n; ++i, phase ^= 1) {
for(int j = 0; j <= m; ++j) {
d[phase ^ 1][j] = d[phase][j];
if(j >= w[i]) d[phase ^ 1][j] = max(d[phase ^ 1][j], d[phase][j - w[i]] + p[i]);
}
}
fout << d[phase][m];
return 0;
}