Pagini recente » Cod sursa (job #2103401) | Cod sursa (job #945241) | Cod sursa (job #2555174) | Cod sursa (job #2817121) | Cod sursa (job #2980620)
#include <fstream>
using namespace std;
const int Nmax = 1001;
int dp[Nmax + 5];
int main()
{
ifstream fin("energii.in");
ofstream fout("energii.out");
int n, w, e, c;
fin >> n >> w;
dp[0] = 0;
for(int i = 1; i <= w; i++){
dp[i] = -1;
}
for(int i = 1; i <= n; i++){
fin >> e >> c;
for(int j = w; j >= e; j--){
if(dp[j - e] != -1){
if(dp[j] == -1){
dp[j] = dp[j - e] + c;
}
else{
dp[j] = min(dp[j], dp[j - e] + c);
}
}
}
for(int j = e - 1; j >= 1; j--){
if(dp[j] == -1){
dp[j] = c;
}
else{
dp[j] = min(dp[j], c);
}
}
}
fout << dp[w];
return 0;
}