Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MAX = 101
- INF = 1000000000
- prev = [-INF] * MAX
- next = [-INF] * MAX
- next[0] = 0
- t = price = 0
- with open("in.csv") as f:
- for line in f:
- splitted = line.split(',')
- try:
- t = int(splitted[0])
- price = int(splitted[1])
- except:
- continue
- if t == 100:
- break
- for i in xrange(MAX):
- prev[i] = next[i]
- for i in xrange(MAX):
- if prev[i] == -INF:
- continue
- if i < MAX - 1:
- next[i + 1] = max(next[i + 1], prev[i] - price)
- if i > 0:
- next[i - 1] = max(next[i - 1], prev[i] + price)
- result = -INF
- for i in xrange(MAX):
- next[i] += i * price
- result = max(next[i], result)
- print result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement