Pagini recente » Cod sursa (job #77252) | Cod sursa (job #1619442) | Cod sursa (job #877968) | Cod sursa (job #565833) | Cod sursa (job #2434244)
#include <fstream>
#include <set>
using namespace std;
ifstream fin("energii.in");
ofstream fout("energii.out");
int costM[1005][5005];
int main()
{
int n, need;
fin >> n >> need;
int minn = 20001000;
for(int i = 1; i <= n; ++i){
int cant, cost;
fin >> cant >> cost;
if(i == 1)
costM[1][cant] = cost;
else {
costM[i][cant] = cost;
for(int j = cant + 1; j <= 5000; ++j)
{
if(costM[i - 1][j - cant] != 0){
costM[i][j] = costM[i - 1][j - cant] + cost;
if(j >= need)
minn = min(minn, costM[i][j]);
}
}
}
if(cant >= need)
minn = min(minn, cost);
}
fout << (minn == 20001000 ? -1 : minn) << '\n';
return 0;
}