Pagini recente » Cod sursa (job #1580189) | Cod sursa (job #1652992) | Cod sursa (job #911256) | Cod sursa (job #496761) | Cod sursa (job #2615840)
#include <iostream>
#include <fstream>
#define INF 1000000000
using namespace std;
ifstream fin("energii.in");
ofstream fout("energii.out");
int n, w, v[5005];
int main() {
fin >> n >> w;
for(int i = 1; i <= w; i++)
v[i] = INF;
for(int i = 1; i <= n; i++) {
int x, y;
fin >> x >> y;
for(int j = w; j >= 0; j--) {
int next = j + x;
if(next > w)
next = w;
v[next] = min(v[j] + y, v[next]);
}
}
if(v[w] != INF)
fout << v[w];
else
fout << -1;
return 0;
}