Pagini recente » Cod sursa (job #1784308) | Cod sursa (job #942463) | Cod sursa (job #1407223) | Cod sursa (job #233243) | Cod sursa (job #1400001)
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream is("energii.in");
ofstream os("energii.out");
const int Emax = 10001;
const int Nmax = 1001;
const int Wmax = 5001;
const int INF = 0x3f3f3f3f;
int n, w, maxe;
int E[Nmax], C[Emax];
vector<int> Cost;
int main()
{
is >> n >> w;
for ( int i = 1; i <= n; ++i )
{
is >> E[i] >> C[i];
maxe = max(maxe, E[i]);
}
Cost = vector<int>(w + maxe + 2, INF);
Cost[0] = 0;
for ( int i = 1; i <= n; ++i )
for ( int j = w; j >= 0; --j )
if ( Cost[j] != INF && Cost[j + E[i]] > Cost[j] + C[i] )
Cost[j + E[i]] = Cost[j] + C[i];
int r;
r = *min_element(Cost.begin() + w, Cost.end());
if ( r == INF )
os << -1;
else
os << r;
is.close();
os.close();
return 0;
}