Pagini recente » Cod sursa (job #1422001) | Cod sursa (job #2385603) | Cod sursa (job #2385610) | Cod sursa (job #2329207) | Cod sursa (job #2516191)
#include <fstream>
#include <vector>
using namespace std;
ifstream in("energii.in");
ofstream out("energii.out");
int n,w,maxx,scost;
const int lim=1003;
struct generator
{
int e,cost;
}v[lim];
vector<pair<int,int> > f;
int main()
{
ios_base::sync_with_stdio(false);
in.tie(0),out.tie(0);
in>>n>>w;
for(int i=1;i<=n;++i)
{
in>>v[i].e>>v[i].cost;
maxx+=v[i].e;
scost+=v[i].cost;
}
if(maxx<w)
{
out<<-1;
return 0;
}
if(maxx==w)
{
out<<scost;
return 0;
}
f.push_back({0,0});
for(int i=1;i<=n;++i)
{
for(int j=f.size()-1;j>=0;--j)
if(f[j].first<w)
{
f.push_back({f[j].first+v[i].e,f[j].second+v[i].cost});
}
}
int minn=0x7fffffff;
for(int j=f.size()-1;j>=0;--j)
if(f[j].second<minn and f[j].first>=w)
minn=f[j].second;
out<<minn;
return 0;
}