Connection Status:
Competition Arena > TimeTravellingCellar
SRM 492 · 2010-03-12 · by dolphinigle · Brute Force, Simulation
Class Name: TimeTravellingCellar
Return Type: int
Method Name: determineProfit
Arg Types: (vector<int>, vector<int>)
Problem Statement

Problem Statement

Gogo owns N wine cellars, numbered 0 through N-1. He possesses a time machine and will use it to advance time in one of the cellars, maturing all the wine inside. However, as a side effect, he must also choose one other cellar and turn back time there, making the wine inside younger.

You are given two int[]s, profit and decay. Advancing time in cellar i will gain Gogo a profit of profit[i]. Turning back time in cellar i will lose him decay[i] in profit. Return the maximum profit that Gogo can gain by advancing time in one cellar and turning time back in another cellar. It is guaranteed that this profit will be positive.

Constraints

  • profit will contain between 2 and 50 elements, inclusive.
  • Each element of profit will be between 1 and 10000, inclusive.
  • decay will contain the same number of elements as profit.
  • Each element of decay will be between 1 and 10000, inclusive.
  • The maximum profit that Gogo can gain will be positive.
Examples
0)
{1,2,3}
{3,1,2}
Returns: 2

Advance time in cellar 2 and turn back time in cellar 1. The total profit is 3 - 1 = 2.

1)
{3,2}
{1,2}
Returns: 1

He can't advance and turn back time in the same cellar.

2)
{50,5743,2919,483,382,5583}
{2823,3479,9955,312,3838,402}
Returns: 5431
3)
{3,3,3}
{1,1,1}
Returns: 2
4)
{10000,10000}
{1,1}
Returns: 9999

Submissions are judged against all 334 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class TimeTravellingCellar with a public method int determineProfit(vector<int> profit, vector<int> decay) · 334 test cases · 2 s / 256 MB per case

Submitting as anonymous