Pagini recente » Cod sursa (job #2214649) | Cod sursa (job #1288162) | Cod sursa (job #509947) | Cod sursa (job #791479) | Cod sursa (job #2981663)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("energii.in");
ofstream fout ("energii.out");
const int kN = 1e4 + 5;
int dp[kN];
int n, W;
int main(){
ios_base::sync_with_stdio(false);
fin >> n >> W;
fill(dp, dp + kN, -1);
dp[0] = 0;
for (int i = 1; i <= n; i++){
int e, c; fin >> e >> c;
for (int j = W; j >= 0; j--){
if (j >= e){
if (dp[j - e] == -1){
continue;
}
if (dp[j] == -1){
dp[j] = dp[j - e] + c;
}
else{
dp[j] = min(dp[j], dp[j - e] + c);
}
}
else{
dp[j] = ((dp[j] == -1) ? c : min(dp[j], c));
}
}
}
fout << dp[W];
}