Pagini recente » Rating Grasune Alexandru Mihai (GrasuneAlexandru) | Cod sursa (job #2137935) | Cod sursa (job #1566770) | Cod sursa (job #1887348) | Cod sursa (job #2357317)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("energii.in");
ofstream fout("energii.out");
const int INF = (1 << 30);
int G,W;
int mat[5010];
int x,y;
vector <int> L;
void Read()
{
fin>>G>>W;
for(int i=1;i<=5002;++i)
mat[i]=INF;
for(int i=1;i<=G;++i)
{
fin>>x>>y;
int l,c;
int n=L.size();
for(int k=0;k<n;++k)
{
l=L[k];
mat[l+x]=min(mat[l+x],mat[l]+y);
L.push_back(l+x);
}
mat[x]=min(mat[x],y);
L.push_back(x);
}
int cost=INF;
for(int i=W;i<=5002;++i)
//fout<<mat[i]<<"\n";
cost=min(cost,mat[i]);
if(cost!=INF)fout<<cost;
else fout<<-1;
}
int main()
{
Read();
return 0;
}