Cody

Problem 2262. GJam 2011 Africa Qualifier B: Optimum Profit

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

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

56.52% Correct | 43.48% Incorrect
Last solution submitted on Jan 24, 2015

Tags

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi