Pagini recente » Cod sursa (job #2478727) | Cod sursa (job #1170526) | Cod sursa (job #1034074) | Cod sursa (job #922473) | Cod sursa (job #2799380)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("energii.in");
ofstream fout("energii.out");
#define MAX=999999999
int n, e[1005], c[1005], w, dp[5005];
int main()
{
fin>>n>>w;
for(int i=1; i<=n; i++)
fin>>e[i]>>c[i];
for(int i=1; i<=n;i++)
dp[i]=MAX;
for(int i=1; i<=n; i++)
for(int j=w; j>0; j--)
if(j<=e[i])
dp[j]=min(dp[j], c[i]);
else
dp[j]=min(dp[j], c[i]+dp[j-e[i]]);
if(dp[w]==MAX)
fout<<-1;
else
fout<<dp[w];
return 0;
}