GSS1 segment tree Problem Link #include <iostream> #include <stdio.h> using namespace std; struct node { long bestSum, leftSum, rightSum, totalSum; }; int n; long t; node seg[200003]; long arr[50003]; node combine(node &lc, node &rc) { node temp; temp.totalSum = lc.totalSum + rc.totalSum; temp.leftSum = max(lc.leftSum, lc.totalSum + rc.leftSum); temp.rightSum = max(rc.rightSum, rc.totalSum + lc.rightSum); temp.bestSum = max(lc.rightSum + rc.leftSum, max(lc.bestSum, rc.bestSum)); return temp; } void buildTree(int l, int r, int index) { if(l == r) { seg[index].bestSum = seg[index].rightSum = seg[index].leftSum = seg[index].totalSum = arr[l]; } else { int mid = l + ((r - l) >> 1); int lchild = (index &l