Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int n;
- int cena[2005], tezina[2005];
- int W;
- int rec(int at, int W_left) {
- if(at == n) {
- return 0;
- }
- int result = -2e9;
- // da ne go zememe elementot
- result = max(result, rec(at + 1, W_left));
- if(W_left - tezina[at] >= 0)
- result = max(result, rec(at + 1, W_left - tezina[at]) + cena[at]);
- return result;
- }
- int main() {
- cin >> n;
- for(int i = 0; i < n; i++) {
- cin >> cena[i] >> tezina[i];
- }
- cin >> W;
- cout << rec(0, W) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement