Created
July 22, 2017 07:55
-
-
Save nerohoop/7d575ac66e994978ab54b509bd5d6f6b to your computer and use it in GitHub Desktop.
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
n = input() | |
a = [input() for _ in xrange(n)] | |
c, desc_buf = [1]*n, [] | |
for i in xrange(1, n): | |
if a[i] < a[i-1]: | |
if not desc_buf: | |
desc_buf = [i-1] | |
desc_buf.append(i) | |
if not i == n-1: | |
continue | |
if a[i] > a[i-1]: | |
c[i] = c[i-1] + 1 | |
if desc_buf: | |
for extra, idx in enumerate(desc_buf[::-1]): | |
c[idx] = max(c[idx], extra + 1) | |
del desc_buf[:] | |
print sum(c) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment