Pagini recente » Cod sursa (job #402351) | Cod sursa (job #1780032) | Cod sursa (job #1943068) | Cod sursa (job #1630795) | Cod sursa (job #766986)
Cod sursa(job #766986)
#include<fstream>
#define inf 2000000000
using namespace std;
int n,s,sol[5002],C[1002],G[1002],i,j;
char uz[5003][1003];
int main()
{
ifstream f("energii.in");ofstream g("energii.out");
f>>n>>s;
for(i=1;i<=n;i++)
f>>G[i]>>C[i];
for(i=1;i<=s;i++)
{ sol[i]=inf;
for(j=1;j<=n;j++)
if(sol[i-G[j]]+C[j]<sol[i] && !uz[i-G[j]][j] && G[j]<=i)
{
sol[i]=sol[i-G[j]]+C[j];
uz[i][j]='1';
}
}
if(sol[s]==inf)g<<"-1"; else
g<<sol[s]<<'\n';
f.close();g.close();
return 0;}