Pagini recente » Cod sursa (job #479570) | Cod sursa (job #1153751) | Istoria paginii utilizator/sygandreiionita | Istoria paginii utilizator/anky_mary | Cod sursa (job #202030)
Cod sursa(job #202030)
#include<fstream>
#include<iostream>
using namespace std;
int g;
int w;
int e[1001];
int c[1001];
long costuri[5001/*10000001*/];
int main(void)
{
freopen("energii.in", "r", stdin);
freopen("energii.out", "w", stdout);
cin >> g;
cin >> w;
long max = 0;
for(int i=0;i<g;++i)
{
cin >> e[i] >> c[i];
max += e[i];
}
memset(costuri, -1, sizeof(costuri));
costuri[0] = 0;
long min = 20000001;
for(int j=0;j<g;++j)
{
for(long i = w; i>=1; --i)
{
if(e[j] <= i)
{
if(costuri[i-e[j]] > -1)
{
if(costuri[i] == -1)
costuri[i] = costuri[i-e[j]] + c[j];
else
if(costuri[i] < costuri[i-e[j]] + c[j])
costuri[i] = costuri[i-e[j]] + c[j];
}
}else
{
if(costuri[i] == -1)
costuri[i] = c[j];
else
if(costuri[i] < c[j])
costuri[i] = c[j];
}
//if(i>=w && costuri[i] != -1)
// if(costuri[i] < min)
// min = costuri[i];
}
}
// if(min == 20000001)
// cout << -1 << endl;
// else
cout << costuri[w] << endl;
return 0;
}