-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcandy_2.py
More file actions
41 lines (28 loc) · 711 Bytes
/
candy_2.py
File metadata and controls
41 lines (28 loc) · 711 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the candies function below.
def candies(n, arr):
dp = [1]*n
for i in range(1, n):
if arr[i] > arr[i-1]:
dp[i] = dp[i-1] + 1
for j in range(n-1, 0, -1):
if arr[j] < arr[j-1] and dp[j] >= dp[j-1]:
dp[j-1] = dp[j] + 1
return sum(dp)
print(dp)
return sum(dp)
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
n = int(input())
arr = []
for _ in range(n):
arr_item = int(input())
arr.append(arr_item)
result = candies(n, arr)
fptr.write(str(result) + '\n')
fptr.close()