-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArray Manipulation.py
78 lines (53 loc) · 1.82 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Array Manipulation
# Starting with a 1-indexed array of zeros and a list of operations, for each operation add a value to each the array element between two given indices, inclusive. Once all operations have been performed, return the maximum value in the array.
# Example
# Queries are interpreted as follows:
# a b k
# 1 5 3
# 4 8 7
# 6 9 1
# Add the values of between the indices and inclusive:
# index-> 1 2 3 4 5 6 7 8 9 10
# [0,0,0, 0, 0,0,0,0,0, 0]
# [3,3,3, 3, 3,0,0,0,0, 0]
# [3,3,3,10,10,7,7,7,0, 0]
# [3,3,3,10,10,8,8,8,1, 0]
# The largest value is after all operations are performed.
# Function Description
# Complete the function arrayManipulation in the editor below.
# arrayManipulation has the following parameters:
# int n - the number of elements in the array
# int queries[q][3] - a two dimensional array of queries where each queries[i] contains three integers, a, b, and k.
# Returns
# int - the maximum value in the resultant array
import math
import os
import random
import re
import sys
#
# Complete the 'arrayManipulation' function below.
#
# The function is expected to return a LONG_INTEGER.
# The function accepts following parameters:
# 1. INTEGER n
# 2. 2D_INTEGER_ARRAY queries
#
def arrayManipulation(n, queries):
# Write your code here
l = [0 for i in range(n)]
for q in queries:
for i in range(q[0]-1,q[1]):
l[i] += q[2]
return max(l)
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
first_multiple_input = input().rstrip().split()
n = int(first_multiple_input[0])
m = int(first_multiple_input[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()