Help in KGSS- Maximum Sum

I have solved the problem KGSS-Maximum Sum from SPOJ using segment tree in Java and I am getting TLE. Can anyone help me to further optimize my code?

Problem link: SPOJ.com - Problem KGSS
Solution link: Online Compiler and IDE - GeeksforGeeks

@curio please help me in this pronlem

use segment tree(st) point update and range max query

  1. find maximum in a [x,y], let it be i
  2. store a[i] somewhere and update st node i to 0
  3. find maximum in [x,y], let it be j, by constraints of problem u can be sure i!=j
  4. ans=a[i]+a[j]
  5. update st node i again to its original value

however, since you asked for code, here you go.

1 Like