Pagini recente » Cod sursa (job #2478413) | Cod sursa (job #2678994) | Cod sursa (job #1233774) | Cod sursa (job #5860) | Cod sursa (job #2946941)
#include <fstream>
#include <vector>
using namespace std;
ifstream cin ("energii.in");
ofstream cout ("energii.out");
int s, n, k, maxim;
struct gen
{
int E,C;
};
vector <gen> v(1001);
vector <int> profit;
inline void citire()
{
cin >> n >> k;
for (int i=0; i<n; i++)
{
cin >> v[i].E >> v[i].C;
maxim = max(maxim,v[i].E);
s += v[i].E;
}
}
int main ()
{
citire();
profit.resize(maxim+k+1);
if (s < k)
{
cout << -1;
return 0;
}
s = maxim + k + 1;
for (int i=0; i<n; i++)
{
for (int j = s - v[i].E; j>=0; j--)
{
if (profit[j])
{
if (profit[j+v[i].E] == 0)
{
profit[j+v[i].E] = profit[j] + v[i].C;
}
else
profit[j+v[i].E] = min(profit[j+v[i].E], profit[j] + v[i].C);
}
}
if (profit[v[i].E] == 0)
profit[v[i].E] = v[i].C;
else
profit[v[i].E] = min(profit[v[i].E],v[i].C);
}
int raspuns = 10e7;
for (int i = k; i<=s; i++)
{
if (profit[k])
raspuns = min(raspuns,profit[k]);
}
cout << raspuns;
}