Pagini recente » Cod sursa (job #333871) | Rating ---L---- (Ahile30) | Cod sursa (job #2757097) | Cod sursa (job #1382114) | Cod sursa (job #2355170)
#include <bits/stdc++.h>
#define Nmax 5005
using namespace std;
int n, w, v[Nmax], DP[7005], x, y;
int main()
{
ios::sync_with_stdio(false);
freopen("energii.in","r",stdin);
freopen("energii.out","w",stdout);
cin >> n >> w;
memset(DP,0x3f,sizeof(DP));
DP[0] = 0;
for (int i=1;i<=n;i++){
cin >> x >> y;
for (int j=6005;j>=x;j--)
DP[j] = min(DP[j], DP[j-x] + y);
}
int ans = 1e9+2;
for (int i=6000;i>=w;i--)
ans = min(ans,DP[i]);
if (ans > 1e9) cout << -1 << '\n';
else cout << ans << '\n';
return 0;
}