Pagini recente » Cod sursa (job #201273) | Cod sursa (job #3036962) | Atasamentele paginii Profil Cristian2007 | Cod sursa (job #97559) | Cod sursa (job #3330293)
/*
https://www.infoarena.ro/problema/energii
*/
#include <fstream>
using namespace std;
const int INF = 10015;
const int E = 5000;
struct generator
{
int e, c;
};
int cost[E+1];
int main()
{
ifstream in("energii.in");
ofstream out("energii.out");
int n, w;
in >> n >> w;
for (int j = 1; j <= w + 1; j++)
{
cost[j] = INF;
}
cost[0] = 0;
for (int i = 0; i < n; i++)
{
generator g;
in >> g.e >> g.c;
for (int j = w - 1; j >= 0; j--)
{
if (cost[j] != INF)
{
int e_prod = j + g.e;
if (e_prod > w)
{
e_prod = w;
}
if (cost[j] + g.c < cost[e_prod])
{
cost[e_prod] = cost[j] + g.c;
}
}
}
}
if (cost[w] == INF)
{
cost[w] = -1;
}
out << cost[w] << "\n";
in.close();
out.close();
return 0;
}