Pagini recente » Cod sursa (job #491266) | Cod sursa (job #3196321) | Cod sursa (job #1033029) | Cod sursa (job #2487633) | Cod sursa (job #2331502)
#include <fstream>
using namespace std;
ifstream in("rucsac.in");
ofstream out("rucsac.out");
const int N=10005;
int n, k, maxi;
int profit[N], p[N], g[N];
void citire()
{
in>>n>>k;
for(int i=1; i<=n; i++) in>>g[i]>>p[i];
}
int main()
{
citire();
for(int i=1; i<=n; i++) profit[i]=-1;
for(int i=1; i<=n; i++)
for(int j=k-g[i]; j>=0; j--)
if(profit[j]!=1 && profit[j]+p[i]>profit[j+g[i]]) profit[j+g[i]]=profit[j]+p[i];
for(int i=1; i<=k; i++) maxi=max(maxi, profit[i]);
out<<maxi;
return 0;
}