Python: ZWK Segment Tree template
Greedy Sort + ZWK Segment Tree with discretization\npy\nclass SegmentTree:\n    def __init__(self, n):\n        self.n = n\n        self.T = [-1]*2*self.n\n\n  
Greedy Sort + ZWK Segment Tree with discretization\n``` py\nclass SegmentTree:\n    def __init__(self, n):\n        self.n = n\n        self.T = [-1]*2*self.n\n\n    def _set(self, i, val):\n        i += self.n\n        while i:\n            self.T[i] = max(val, self.T[i])\n            i //= 2\n\n    def rangeMax(self, l, r):\n        ans = -1\n        l, r = l+self.n, r+self.n\n        while l<=r:\n            if l%2: ans, l = max(ans, self.T[l]), l+1 # if l is right child\n            if not r%2: ans, r = max(ans, self.T[r]), r-1 # if r is left child\n            l, r = l//2, r//2\n        return ans\n        \nclass Solution:\n    def maximumSumQueries(self, nums1: List[int], nums2: List[int], queries: List[List[int]]) -> List[int]:\n        v2i = {x: i for i, x in enumerate(sorted(set(nums2+[y for _, y in queries])))}\n        A = sorted(zip(nums1, nums2), reverse=True)\n        queries = sorted([q+[i] for i, q in enumerate(queries)], reverse=True)\n        ST = SegmentTree(len(v2i)+1)\n        ans = [-1]*len(queries)\n        j = 0\n        for x, y, i in queries:\n            while j<len(A) and x<=A[j][0]:\n                ST._set(v2i[A[j][1]], A[j][0]+A[j][1])\n                j += 1\n            ans[i] = ST.rangeMax(v2i[y], len(v2i))\n        return ans\n```\n\nGeneral Template:\n``` py\nclass SegmentTree:\n    def __init__(self, n):\n        self.n = n\n        self.T = [0]*2*self.n\n\n    def _build(self, A):\n        for i in range(self.n): \n            self.T[i+self.n] = A[i]\n        for i in reversed(range(self.n)):\n            self.T[i] = self.T[2*i] + self.T[2*i+1]\n    \n    def _add(self, i, val):\n        i += self.n\n        diff = val - self.T[i]\n        while i:\n            self.T[i] += diff\n            i //= 2\n\n    def _set(self, i, val):\n        i += self.n\n        while i:\n            self.T[i] = max(val, self.T[i])\n            i //= 2\n            \n    def rangeSum(self, l, r):\n        ans = 0\n        l, r = l+self.n, r+self.n\n        while l<=r:\n            if l%2: ans, l = ans+self.T[l], l+1 # if l is right child\n            if not r%2: ans, r = ans+self.T[r], r-1 # if r is left child\n            l, r = l//2, r//2\n        return ans\n\n    def rangeMax(self, l, r):\n        ans = 0\n        l, r = l+self.n, r+self.n\n        while l<=r:\n            if l%2: ans, l = max(ans, self.T[l]), l+1 # if l is right child\n            if not r%2: ans, r = max(ans, self.T[r]), r-1 # if r is left child\n            l, r = l//2, r//2\n        return ans\n```
[]