Pagini recente » Cod sursa (job #2979531) | Cod sursa (job #325836) | Cod sursa (job #1216731) | Cod sursa (job #2364414) | Cod sursa (job #2214469)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("energii.in");
ofstream fout ("energii.out");
int dp[5001], e[1001], c[1001], n, w;
int main()
{
fin >> n >> w;
for (int i = 1; i <= n; i++)
fin >> e[i] >> c[i];
int sol = INT_MAX;
dp[0] = 1;
for (int i = 1; i <= n; i++)
for (int j = w; j >= 0; j--)
if (dp[j]) {
if (j + e[i] < w) {
if (dp[j + e[i]])
dp[j + e[i]] = min(dp[j + e[i]], dp[j] + c[i]);
else
dp[j + e[i]] = dp[j] + c[i];
}
else
sol = min(sol, dp[j] + c[i]);
}
if (sol == INT_MAX)
fout << -1;
else
fout << sol - 1;
return 0;
}