Pagini recente » Cod sursa (job #295553) | Cod sursa (job #1584734) | Istoria paginii utilizator/petrica_norby | Cod sursa (job #914247) | Cod sursa (job #1571698)
#include <fstream>
using namespace std;
const int MAXENERGIE = 5002;
const int INF = 1 << 30;
ifstream in("energii.in");
ofstream out("energii.out");
int cost[MAXENERGIE];//costul minim pentru a obtine energia i
//caz special: cost[W] care reprezinta costul minim pentru a da drumul centralei
int w;
int main()
{
int n;
in >> n;
in >> w;
for (int i = 0;i <= w;++i)
cost[i] = INF;
int c, energie;
for (int generator = 1;generator <= n; ++generator)
{
in >> energie >> c;
int poz;
for (int i = w;i >= 0;--i)
{
if (cost[i] == INF)
continue;
poz = min(w, i + energie);
if (cost[poz] > cost[i] + c)
cost[poz] = cost[i] + c;
}
poz = min(energie, w);
if (cost[poz] > c)
cost[poz] = c;
}
out << cost[w];
return 0;
}