Cody

Problem 2262. GJam 2011 Africa Qualifier B: Optimum Profit

Created by Richard Zapor in Community

This Challenge is derived from GJam 2011 Africa: Investing at the Market. Google Code Jam 2014 Kicks Off its Qualifier round April 11. GJam Registration. The Test Suite, at the bottom, contains a full GJam file input read (fgetl and dlmread), process, and Output example.

Determine the single optimal Buy and Sell time to optimize Profit. If multiple cases exist then provide set with minimum Buy cost. Investment buys made in whole units. If no profit is possible return [0 0 0]. Only one Buy/Sell pair occurs.

Input: M,x Where M is Investment and x,size(1,12), is Commodity Buy/Sell Price

Output: BSP, [BuyPt SellPt Profit]

Example: M=100; x=[52 50 25 100 61 63 70 51 71 55 10 5];

Output: 3 4 300

Additional GJam solutions can be found at Example GJam Matlab solutions. Select Find Solutions, change Language to Matlab. There were only 50 Qualifier Matlab entrants in 2013 and a mere 2 Matlab users achieved round 2.

Solution Stats

60.0% Correct | 40.0% Incorrect
Last solution submitted on Nov 25, 2018