Soul stone(beware spoilers ahead!)

4 outoff 2 pass test case
error
question :https://hack.codingblocks.com/contests/c/547/1555

https://ide.codingblocks.com/s/61869

you are using Brute Force O(n^2)
Check constraint n<=10^6
Brute force will not work
Think O(n logn)

ok thanks