Pagini recente » Cod sursa (job #1814199) | Cod sursa (job #1652111) | Cod sursa (job #1147423) | Cod sursa (job #482558) | Cod sursa (job #2535489)
#include <fstream>
std::ifstream f("energii.in");
std::ofstream g("energii.out");
const int NMAX = 50'000;
const int INF = (1LL << 31) - 1;
int G,W,dp[NMAX + 5];
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;
for(int i = 0;i <= NMAX;++i)
dp[i] = INF;
for(int i = 1;i <= G;++i){
for(int j = NMAX;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 <= NMAX;++i)
sol = std::min(sol,dp[i]);
g << sol;
return 0;
}