Pagini recente » Statistici Micula Cristina (Criistina) | Cod sursa (job #2671247) | fmi-no-stress-9-warmup/solutii | Cod sursa (job #3281385) | Cod sursa (job #202029)
Cod sursa(job #202029)
#include<fstream>
#include<iostream>
using namespace std;
int g;
int w;
int e[1001];
int c[1001];
long costuri[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 << min << endl;
return 0;
}