Created
January 30, 2011 14:29
-
-
Save Surgo/802891 to your computer and use it in GitHub Desktop.
SRM492 - div2 - level one
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
"""SRM492 - div2 - level one | |
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. | |
Definition: | |
Class: TimeTravellingCellar | |
Method: determineProfit | |
Parameters: int[], int[] | |
Returns: int | |
Method signature: int determineProfit(int[] profit, int[] decay) | |
""" | |
class TimeTravellingCellar(object): | |
"""Time Travelling Cellar | |
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. | |
>>> cellar = TimeTravellingCellar() | |
>>> print cellar.determineProfit([1,2,3, ], [3,1,2, ]) | |
2 | |
>>> print cellar.determineProfit([3,2, ], [1,2, ]) | |
1 | |
>>> print cellar.determineProfit([3,3,3, ], [1,1,1, ]) | |
2 | |
>>> print cellar.determineProfit([1000,500,250,125, ], [64,32,16,8, ]) | |
992 | |
""" | |
def __init__(self): | |
pass | |
def determineProfit(self, profit=[], decay=[]): | |
m = 0 | |
for i in range(len(profit)): | |
for j in [j for j in range(len(decay)) if j != i]: | |
m = m < profit[i] - decay[j] and profit[i] - decay[j] or m | |
return m | |
if __name__ == '__main__': | |
import doctest | |
doctest.testmod() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment