-
Notifications
You must be signed in to change notification settings - Fork 183
/
05 - Array Manipulation.py
46 lines (37 loc) · 1.02 KB
/
05 - Array Manipulation.py
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
42
43
44
45
46
# ========================
# Information
# ========================
# Direct Link: https://www.hackerrank.com/challenges/crush/problem
# Difficulty: Hard
# Max Score: 60
# Language: Python
# ========================
# Solution
# ========================
import os
# Complete the arrayManipulation function below.
def arrayManipulation(n, queries):
arr = [0]*(n+1)
max_value = 0
total_sum = 0
for query in queries:
l = query[0]
h = query[1]
val = query[2]
arr[l-1] = arr[l-1] + val
arr[h] = arr[h]-val
for value in arr:
total_sum = total_sum + value
max_value = max(max_value, total_sum)
return max_value
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
nm = input().split()
n = int(nm[0])
m = int(nm[1])
QUERIES = []
for _ in range(m):
QUERIES.append(list(map(int, input().rstrip().split())))
RESULT = arrayManipulation(n, QUERIES)
fptr.write(str(RESULT) + '\n')
fptr.close()