Pagini recente » Cod sursa (job #2891171) | Cod sursa (job #1672618) | Cod sursa (job #2727495) | Cod sursa (job #2689708) | Cod sursa (job #3199055)
#include <fstream>
using namespace std;
ifstream fin("energii.in");
ofstream fout("energii.out");
const int N = 1e3, W = 5e3;
int n, cost[W + 1], w, c[N + 1], p[N + 1];
int main()
{
fin >> n >> w;
for(int i = 1; i <= w; i++)
cost[i] = 1e3;
for(int i = 0; i < n; i++)
fin >> c[i] >> p[i];
for(int i = 0; i < n; i++)
for(int j = w - c[i]; j >= 0; j--)
if(cost[j] != 1e3)
cost[j + c[i]] = min(cost[j + c[i]], cost[j] + p[i]);
fout << cost[w];
}