Pagini recente » Cod sursa (job #1694714) | Cod sursa (job #2053226) | Cod sursa (job #3039192) | Cod sursa (job #1642445) | Cod sursa (job #2849764)
#include <bits/stdc++.h>
#define WMAX 5005
#define INF 1000000005
using namespace std;
/*******************************/
// INPUT / OUTPUT
ifstream f("energii.in");
ofstream g("energii.out");
/*******************************/
/// GLOBAL DECLARATIONS
int G, W;
int ans;
int dp[WMAX]; // costul minim pentru a face i energie
vector <pair <int, int> > generators;
/*******************************/
/// FUNCTIONS
void ReadInput();
void Solution();
void Output();
/*******************************/
///-------------------------------------
inline void ReadInput()
{
f >> G >> W;
int energy, cost;
for (int i = 0 ; i < G ; ++ i)
{
f >> energy >> cost;
generators.push_back({energy, cost});
}
}
///-------------------------------------
inline void Solution()
{
memset(dp, INF, sizeof(dp));
dp[0] = 0;
for (int energy = 1 ; energy <= W ; ++ energy)
{
for (auto generator: generators)
{
if (generator.first <= energy)
{
dp[energy] = min(dp[energy], dp[energy - generator.first] + generator.second);
}
}
}
if (dp[W] != INF) ans = dp[W];
else ans = -1;
}
///-------------------------------------
inline void Output()
{
g << ans;
}
///-------------------------------------
int main()
{
ReadInput();
Solution();
Output();
return 0;
}