-
- for (int i = 0; i < n; i++) {
-
- ll rightMax = query(prefixTree, 1, 0, _n — 1, i + 1, ng[i] — 1) — prefixSum[i];
-
- ll leftMax = query(suffixTree, 1, 0, _n — 1, pg[i] + 1, i — 1) — suffixSum[i];
-
- if (max(leftMax, rightMax) > 0) {
-
- flag = false;
-
- break;
-
- }
-
- }
why they are selecting the lower index as i + 1 but not i. According to me it was something like
ll rightMax = query(prefixTree, 1, 0, _n — 1, i, ng[i] — 1) — prefixSum[i-1];**