-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray_range_diff.go
More file actions
46 lines (36 loc) · 1010 Bytes
/
array_range_diff.go
File metadata and controls
46 lines (36 loc) · 1010 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
45
46
package main
import "fmt"
import "math"
func max(a,b int) int{
if a>b {
return a
} else {
return b
}
}
func main() {
//Enter your code here. Read input from STDIN. Print output to STDOUT
maxNumRange,numOfIterations := 0,0
_,err := fmt.Scanf("%d %d",&maxNumRange,&numOfIterations)
if err == nil {
start,end,sum := 0,0,0
inputArray := make([]int,maxNumRange+1)
for numOfIterations>0 {
_,err := fmt.Scanf("%d %d %d",&start,&end,&sum)
if err == nil {
inputArray[start]+=sum
if end+1<=maxNumRange {
inputArray[end+1]-=sum
}
}
numOfIterations-=1
}
x := 0
maxNum := math.MinInt32
for i:= 1 ; i<=maxNumRange ; i+=1 {
x+=inputArray[i]
maxNum = max(maxNum,x)
}
fmt.Println(maxNum)
}
}