Pagini recente » Cod sursa (job #1356148) | Cod sursa (job #2938012) | Cod sursa (job #2328051) | Cod sursa (job #1795561) | Cod sursa (job #2434223)
#include <fstream>
#include <set>
using namespace std;
ifstream fin("energii.in");
ofstream fout("energii.out");
int costM[5005];
set<int> ToCheck, toAdd;
int main()
{
int n, need;
fin >> n >> need;
for(int i = 1; i <= 5001; ++i)
costM[i] = 10000;
for(int i = 1; i <= n; ++i){
int cant, cost;
fin >> cant >> cost;
costM[cant] = min(costM[cant], cost);
for(auto it : ToCheck){
costM[it+ cant] = min(costM[it + cant], costM[it] + cost);
toAdd.insert(it+ cant);
}
ToCheck.insert(toAdd.begin(), toAdd.end());
ToCheck.insert(cant);
toAdd.clear();
}
fout << costM[need] << '\n';
return 0;
}