Pagini recente » Cod sursa (job #1856032) | Cod sursa (job #2483513) | Cod sursa (job #2035780) | Cod sursa (job #946819) | Cod sursa (job #2712902)
#include <bits/stdc++.h>
using namespace std;
int d[10005];
int main()
{
freopen("energii.in", "r", stdin);
freopen("energii.out", "w", stdout);
int n, a, x, y, ans = -1;
scanf("%d%d", &n, &a);
d[0] = 0;
for(int i = 1; i < a; i++) d[i] = -1;
for(int i = 1; i <= n; i++)
{
scanf("%d%d", &x, &y);
for(int i = a - 1; i >= 0; i--)
if(d[i] != -1 and i + x >= a)
ans = (ans == -1 ? d[i] + y : min(ans, d[i] + y));
else if(d[i] != -1)
d[i + x] = (d[i + x] == -1 ? d[i] + y : min(d[i] + y, d[i + x]));
}
printf("%d", ans);
return 0;
}