Google Code Jam - Store Credit
Leaving alone an UB (which is already addressed), let's look at an actual solution, the credeit_pos function.


  From this list you would like to buy two items that add up to the entire value of the credit.


In a programming terms: given a range, find two values which add up to the given value.

The proposed solution is




for each elements in a range,
    try to find a peer adding up to a target



It is correct but an implementation has quadratic complexity. It feels wrong. Every time you work with a linear range and end up with a quadratic algorithm, ask yourself if it can be improved if the range was sorted (sort is cheap comparing to quadratic). In this case it can be indeed: finding (or failing to find) a peer in a sorted range is a binary search (\$\log(n)\$), which drives an overall complexity to \$n \log(n)\$.

Summing up, the template is



std::sort(std::begin(prices), std::end(prices));
for (auto it = std::begin(prices); it != std::end(prices); ++it) {
    auto peer = std::upper_bound(it, std::end(prices), target - *it);
    if (*it + * peer == credit) return std::make_pair(it, peer);
 } 


PS: since the problem statement guarantees that the solution exists, I didn't bother to check that peer != end(prices).

PPS: the second phase could be completed in a linear time, but due to presence of sort it doesn't matter here.