You are viewing a single comment's thread. Return to all comments →
The same solution in Scala
object Solution { def main(args: Array[String]) = { val scan = new java.util.Scanner(System.in) val n = scan.nextInt() val m = scan.nextInt() val arr:Array[Long] = Array.fill(n)(0) var lower: Int =0 var upper:Int =0 var sum:Long=0 for{ i <- 0 until m }{ lower=scan.nextInt() upper=scan.nextInt() sum=scan.nextInt() arr.update(lower-1,arr(lower-1)+sum) if(upper<n) arr.update(upper,(arr(upper)-sum)) } var max: Long = 0; var temp: Long = 0; for{ i <- 0 until n }{ temp = temp+arr(i) if(temp>max) max=temp } System.out.println(max) } }
Seems like cookies are disabled on this browser, please enable them to open this website
Array Manipulation
You are viewing a single comment's thread. Return to all comments →
The same solution in Scala