Pagini recente » Cod sursa (job #3174844) | Cod sursa (job #2672328) | Cod sursa (job #268351) | Cod sursa (job #1907786) | Cod sursa (job #2480012)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("nrcuv.in");
ofstream fout ("nrcuv.out");
const int N = 5005, limit = 2e9;
int power[N / 5], cost[N / 5], d[N / 5][N];
int main()
{
ios::sync_with_stdio(false);
fin.tie(0);
int n, m;
fin >> n >> m;
int mn = 10000;
for(int i = 1; i <= n; ++i) fin >> power[i] >> cost[i];
for(int i = 1; i <= n; ++i) {
for(int j = 0; j <= mn; ++j) {
d[i][j] = d[i - 1][j];
if(j >= cost[i]) d[i][j] = max(d[i][j], d[i - 1][j - cost[i]] + power[i]);
if(d[i][j] >= m) mn = min(mn, j);
}
}
for(int i = 0; i <= 10000; ++i) {
if(d[n][i] >= m) {
fout << i << "\n";
return 0;
}
}
fout << "-1";
return 0;
}