Pagini recente » Cod sursa (job #1345723) | Borderou de evaluare (job #1567176) | Cod sursa (job #1350083) | Cod sursa (job #415835) | Cod sursa (job #752200)
Cod sursa(job #752200)
#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 [10000005];
int main () {
freopen ("energii.in", "r", stdin);
freopen ("energii.out", "w", stdout);
int n, S = 0, W, i, j, minn;
scanf ("%d%d", &n, &W);
for (i = 1; i <= n; ++ i) {
scanf ("%d%d", &Gen [i] . e, &Gen [i] . c);
}
//sort (Gen + 1, Gen + n + 1, cmp);
S = W * 3;
pot [0] . OK = 1;
minn = 1203320000;
for (i = 1; i <= n; ++ i) {
for (j = S - 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 >= W && 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);
}