Pagini recente » Cod sursa (job #3039971) | Cod sursa (job #3036647) | Cod sursa (job #646026) | Cod sursa (job #2061249) | Cod sursa (job #179567)
Cod sursa(job #179567)
#include <stdio.h>
#include <iostream>
#include <fstream>
using namespace std;
int big[5005];
int c[1001],w[1001];
int main(){
int n,m,i,j,k;
ifstream in("energii.in" );
ofstream out("energii.out");
in >> n >> m;
for (i=0;i<=m;i++)
big[i] = -1;
for (i=0;i<n;i++)
in >> w[i] >> c[i];
big[0] = 0;
for (i=0;i<n;i++)
for (j=m;j>=0;j--)
if (big[j] != -1){
int rel = j + w[i];
if (rel > m) rel = m;
int val = big[j] + c[i];
if (big[rel] == -1 || (big[rel] > val ))
big[rel] = val;
}
out << big[m];
in.close();
out.close();
return 0;
}