Pagini recente » Cod sursa (job #2038700) | Cod sursa (job #1680152) | Cod sursa (job #2442137) | Cod sursa (job #252813) | Cod sursa (job #752192)
Cod sursa(job #752192)
#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 [30005];
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;
minn = 1203320000;
for (i = 1; i <= n; ++ i) {
for (j = 20005 - 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;
}
if (j + Gen [i] . e >= S && pot [j + Gen [i] . e] . c < minn)
minn = pot [j + Gen [i] . e] . c;
}
}
}
if (minn == 1203320000)
printf ("-1\n");
else
printf ("%d\n", minn);
}