Pagini recente » Cod sursa (job #1014512) | Cod sursa (job #2903078) | Cod sursa (job #1143007) | Cod sursa (job #405683) | Cod sursa (job #2089912)
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <vector>
#include <queue>
#include <algorithm>
#if 1
#define pv(x) cout<<#x<<" = "<<x<<"; ";cout.flush()
#define pn cout<<endl
#else
#define pv(x)
#define pn
#endif
using namespace std;
ifstream in("rucsac.in");
ofstream out("rucsac.out");
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
const int GMax = 1e4 + 5;
int N,G;
int dp[2][GMax];
int main() {
in>>N>>G;
for (int i=1;i <= N;++i) {
int value,weight;
in>>weight>>value;
for (int j=1;j <= G;++j) {
dp[1][j] = (j < weight) ? dp[0][j] : max(dp[0][j],dp[0][j-weight] + value);
}
for (int j=1;j <= G;++j) {
dp[0][j] = dp[1][j];
}
}
out<<dp[0][G];
return 0;
}