You are given a list of prices (non-negative integers) $$ P=<P_1, P_2, ..., P_n> $$, where the prices $P_i$ appear in non-decreasing order. Moreover, you have access to an oracle that can be queried with an integer $a$ and returns "yes" if and only if $a \le k$ for some unknown integer $k$. Each query to the oracle requires constant time.
The goal is that of finding a subset $S$ of $\{1, \dots,n\}$ such that the quantity $\sigma(S) = \sum_{i \in S} P_i$ is at most $k$ and $\sigma(S)$ is maximized.
Is there a way to solve this problem in $O(n)$ time?
For example, if $$ P=<P_1=3, P_2=5, P_3=10> $$ and the unknown integer $k$ is $16$, the best choice of $S$ is $\{2,3\}$ and $\sigma(S) = 15$.