Pagini recente » Cod sursa (job #1359288) | Cod sursa (job #2888636) | Cod sursa (job #2138802) | Cod sursa (job #1902790) | Cod sursa (job #2480015)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("energii.in");
ofstream fout ("energii.out");
const int N = 5005, limit = 2e9;
int power[N / 5], cost[N / 5], d[N / 5][N];
pair < int, int> type[N / 5];
bool cmp(pair < int, int > a, pair <int, int> b)
{
return ((a.first > b.first) || (a.first == b.first && a.second < b.second));
}
int main()
{
ios::sync_with_stdio(false);
fin.tie(0);
int n, m;
fin >> n >> m;
int mn = 10001;
for(int i = 1; i <= n; ++i) fin >> type[i].first >> type[i].second;
sort(type + 1, type + 1 + n, cmp);
for(int i = 1; i <= n; ++i) {
for(int j = 0; j <= mn; ++j) {
d[i][j] = d[i - 1][j];
if(j >= type[i].second) d[i][j] = max(d[i][j], d[i - 1][j - type[i].second] + type[i].first);
if(d[i][j] >= m) mn = min(mn, j);
}
}
fout << ((mn == 10001) ? -1 : mn);
return 0;
}