Pagini recente » Cod sursa (job #1520773) | Cod sursa (job #1839650) | Cod sursa (job #2564530) | Cod sursa (job #2703898) | Cod sursa (job #752189)
Cod sursa(job #752189)
#include <cstdio>
#include <algorithm>
using namespace std;
struct EnergieCostint {
int e, c;
};
struct PotCostbool {
bool OK;
int c;
};
bool cmp (const EnergieCostint a, const EnergieCostint b) {
if (a . e == b . e) return (a . c < b . c);
return a . e < b . e;
}
EnergieCostint Gen [1005];
PotCostbool pot [100005];
int main () {
freopen ("energii.in", "r", stdin);
freopen ("energii.out", "w", stdout);
int n, S, i, j, minn;
scanf ("%d%d", &n, &S);
for (i = 1; i <= n; ++ i)
scanf ("%d%d", &Gen [i] . e, &Gen [i] . c);
sort (Gen + 1, Gen + n + 1, cmp);
pot [0] . OK = 1;
for (i = 1; i <= n; ++ i) {
for (j = 100005 - Gen [i] . e; j >= 0; -- j) {
if (pot [j] . OK == 1) {
pot [j + Gen [i] . e] . OK = 1;
if ((pot [j + Gen [i] . e] . c != 0) && (pot [j] . c + Gen [i] . c < pot [j + Gen [i] . e] . c)) {
pot [j + Gen [i] . e] . c = pot [j] . c + Gen [i] . c;
}
else
if (pot [j + Gen [i] . e] . c == 0) {
pot [j + Gen [i] . e] . c = pot [j] . c + Gen [i] . c;
}
}
}
}
minn = 40000;
for (i = S; i <= 100005; ++ i) {
if (pot [i] . OK && pot [i] . c >= 1 && pot [i] . c < minn)
minn = pot [i] . c;
}
if (minn == 40000)
printf ("-1\n");
else
printf ("%d\n", minn);
}