This algorithm is known as the Knapsack Problem, specifically the 0/1 Knapsack Problem. Below is a Python code that solves the 0/1 Knapsack Problem recursively:

```python
def knapsack_recursive(p, w, W, n):
    if n == 0 or W == 0:
        return 0, []
    
    if w[n - 1] > W:
        return knapsack_recursive(p, w, W, n - 1)
    else:
        with_element_p, with_elements_list = knapsack_recursive(p, w, W - w[n - 1], n - 1)
        with_element_p += p[n - 1]
        with_element_list = with_elements_list + [n - 1]
        
        without_element_p, without_elements_list = knapsack_recursive(p, w, W, n - 1)
        
        if with_element_p > without_element_p:
            return with_element_p, with_element_list
        else:
            return without_element_p, without_elements_list

# Example usage
p = [60, 100, 120]
w = [10, 20, 30]
W = 50
n = len(p)

max_profit, selected_elements = knapsack_recursive(p, w, W, n)
print("Maximum sum of selected elements: ", max_profit)
print("Selected elements indices: ", selected_elements)
```

Please note that this is a naive recursive implementation and may not be efficient for large inputs. Dynamic programming is usually used for more efficient solving of the Knapsack Problem.