Pagini recente » Cod sursa (job #1819153) | Cod sursa (job #2917235) | Cod sursa (job #692235) | Cod sursa (job #1383041) | Cod sursa (job #2327636)
//#include <iostream>
#include <cstdio>
#include <algorithm>
#include <time.h>
#include <queue>
#include <cmath>
#include <stack>
#include <fstream>
#include <bitset>
#include <set>
using namespace std;
#define nl '\n'
#define all(v) v.begin(),v.end()
#define eb(x) emplace_back(x)
#define ull unsigned long long
#define File "energii""."
#define N 1002
#define M 10003
ifstream cin(File"in");
ofstream cout(File"out");
template<class a, class type>
void print(a v, type t) {
for_each(all(v), [](type x) { cout << x << ' '; });
cout << nl;
}
int n, E, e[N], c[N];
int dp[M + 7];
int main() {
ios_base::sync_with_stdio(false);
clock_t tStart = clock();
cin >> n >> E;
for (int i = 0; i < n; ++i) {
cin >> e[i] >> c[i];
}
for (int i = 0; i < n; ++i) {
for (int j = M; j >= c[i]; --j)
dp[j] = max(dp[j], e[i] + dp[j - c[i]]);
}
for (int i = 0; i <= M; ++i)
if (dp[i] >= E) {
cout << i;
printf("\nTime taken: %.2fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
return 0;
}
cout << -1;
printf("\nTime taken: %.2fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
}