Pagini recente » Cod sursa (job #2251712) | Cod sursa (job #1271673) | Cod sursa (job #1340227) | Cod sursa (job #1166512) | Cod sursa (job #1209507)
#include <fstream>
#include <cstring>
#define INF 0x3f3f3f
using namespace std;
ifstream is ("energii.in");
ofstream os ("energii.out");
int e[1001], c[1001], sol[100001];
int n, w, wmax;
void Read();
int main()
{
Read();
for(int i = 1; i <= w; ++i)
sol[i] = INF;
for(int i = 1; i <= n; ++i)
for(int j = w; j >= 1; --j)
{
if(e[i]>j)
sol[j]=min(c[i],sol[j]);
else
sol[j]=min(sol[j-e[i]]+c[i],sol[j]);
}
if(sol[w] == INF)
os << -1;
else
os << sol[w];
}
void Read()
{
is >> n >> w;
for(int i = 1; i <= n; ++i)
is >> e[i] >> c[i];
}