forked from codehouseindia/Python-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray Manipulation
More file actions
43 lines (31 loc) · 734 Bytes
/
Array Manipulation
File metadata and controls
43 lines (31 loc) · 734 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
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the arrayManipulation function below.
def arrayManipulation(n, q):
l=[0]*(n+1)
for i in range(len(q)):
a=q[i][0]
b=q[i][1]
k=q[i][2]
l[a-1]=l[a-1]+k
l[b]=l[b]-k
m = x = 0
for i in l:
x=x+i;
if(m<x): m=x;
return(m)
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()