Pagini recente » Cod sursa (job #2853597) | Cod sursa (job #1651584) | Profil ana_maria_zota | Cod sursa (job #308893) | Cod sursa (job #1265759)
#include <fstream>
using namespace std;
ifstream in("energii.in");
ofstream out("energii.out");
const int gmax = 1000 , wmax = 5000 , infinit = 10000001;
int v[wmax + 1] , e[gmax + 1] , c[gmax + 1];
int g , w;
int main()
{
in >> g >> w;
for(int i = 1 ; i <= g ; i++)
in >> e[i] >> c[i];
for(int i = 1 ; i <= w ; i++)
v[i] = infinit;
for(int i = 1 ; i <= g ; i++)
for(int j = w - 1 ; j >= 0 ; j--)
if(v[j] + c[i] < v[j + e[i]])
v[j + e[i]] = v[j] + c[i];
if(v[w] == infinit)
out << "-1\n";
else
out << v[w] << '\n';
return 0;
}