Pagini recente » Cod sursa (job #2580196) | Cod sursa (job #2604504) | Cod sursa (job #216734) | Cod sursa (job #2715900) | Cod sursa (job #2535492)
#include <fstream>
std::ifstream f("energii.in");
std::ofstream g("energii.out");
const int NMAX = 50'0000;
const int INF = (1LL << 31) - 1;
int G,W,dp[NMAX + 5],s;
std::pair<int,int>v[NMAX + 5];
int main(){
f >> G >> W;
for(int i = 1;i <= G;++i){
f >> v[i].first >> v[i].second;
s += v[i].first;
}
for(int i = 0;i <= s;++i)
dp[i] = INF;
for(int i = 1;i <= G;++i){
for(int j = s;j - v[i].first >= 0;--j)
if(dp[j - v[i].first] != INF)
dp[j] = std::min(dp[j],dp[j - v[i].first] + v[i].second);
dp[v[i].first] = std::min(dp[v[i].first],v[i].second);
}
int sol = INF;
for(int i = W;i <= s;++i)
sol = std::min(sol,dp[i]);
g << sol;
return 0;
}