I was getting run time error on this code for this question :- NICEARRAY
fun main() {
val n = readln().toInt() // T
val result = mutableListOf<String>()
var b : Long = 0
var negativeNums = 0
var positiveNums = 0
for (k in 0 until n) {
val m = readln().split(' ') // m[1]
val a = readln().split(' ') // N
for(i in 0 until a.size) {
b = b + (a[i].toLong()/m[1].toLong())
if(a[i].toLong() % m[1].toLong() != 0.toLong()) {
if(a[i].toLong() < 0.toLong())
negativeNums = negativeNums + 1
else
positiveNums = positiveNums + 1
}
}
if(b == 0.toLong())
result.add("YES")
else if(b < 0.toLong() && (positiveNums + b) >= 0.toLong()) {
result.add("YES")
} else if(b > 0.toLong() && (b - negativeNums) <= 0.toLong()) {
result.add("YES")
} else
result.add("NO")
b = 0
negativeNums = 0
positiveNums = 0
}
for (i in result)
println(i)
}
Can someone please explain me why?