Demonstration Task 3: Fruit

Jack and Jill are driving from Niagara Falls to Waterloo. Along the way, they pass several fruit stands. Each fruit stand sell baskets of cherries at one price, and baskets of peaches at another price. Jack wants to buy a basket of cherries, and Jill wants to buy a basket of peaches. They wish to stop at only one fruit stand. Which fruit stand should they stop at to minimize the total cost?

You are to implement a procedure stopat(N,C,P). N is the number of fruit stands. The fruit stands are numbered from 0 to N-1. C and P are arrays representing the prices of cherries and peaches at each fruit stand, in dollars. C[i] is the price of a basket of cherries at the fruit stand numbered i. P[i] is the price of a basket peaches at the fruit stand numbered i. stopat(N,C,P) must return the number of the first fruit stand that has the lowest possible total price for a basket of cherries and a basket of peaches.

Subtask 1 [50 points]

Assume N≤10. The prices for baskets of cherries and peaches will be between 1 and 100 dollars each.

Subtask 2 [50 points]

Assume that N≤1000. The prices for baskets of cherries and peaches will be between 1 and 1000 dollars each.

Implementation Details