cp_guy
1
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
tamo11
2
use segment tree(st) point update and range max query
- find maximum in a [x,y], let it be i
- store a[i] somewhere and update st node i to 0
- find maximum in [x,y], let it be j, by constraints of problem u can be sure i!=j
- ans=a[i]+a[j]
- update st node i again to its original value
however, since you asked for code, here you go.
1 Like