-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathArrayManipulation.py
More file actions
44 lines (33 loc) · 861 Bytes
/
ArrayManipulation.py
File metadata and controls
44 lines (33 loc) · 861 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
42
43
44
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the arrayManipulation function below.
def arrayManipulation(n, queries):
res = [0]*(n+1)
for row in range(len(queries)):
a = queries[row][0]
b = queries[row][1]
k = queries[row][2]
res[a-1] += k
res[b] -= k
sm = 0
mx = 0
for i in range(len(res)):
sm += res[i]
if sm > mx:
mx = sm
return mx
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()