Created
September 19, 2015 14:23
-
-
Save markroxor/38fcb56e1d06fb3a6292 to your computer and use it in GitHub Desktop.
HackerRank DP Practise Candies
This file contains hidden or 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
from sys import stdin | |
nex = iter(map(int,stdin.read().split())).next | |
n = nex() | |
list = [] | |
lt = [] | |
rt = [] | |
for i in xrange(n): | |
list.append(nex()) | |
lt.append(1) | |
rt.append(1) | |
for i in xrange(1,n): | |
if(list[i]>list[i-1]): | |
lt[i] = lt[i-1] + 1 | |
for i in xrange(n-2,-1,-1): | |
if(list[i]>list[i+1]): | |
rt[i] = rt[i+1] + 1 | |
for i in xrange(n): | |
list[i] = max(lt[i],rt[i]) | |
print sum(list) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment