Simple Java Solution Map
\nclass Solution {\n    public void update(TreeMap<Integer,Integer>map,int num,int sum){\n        Map.Entry<Integer,Integer>entry=map.floorEntry(num);\n        
```\nclass Solution {\n    public void update(TreeMap<Integer,Integer>map,int num,int sum){\n        Map.Entry<Integer,Integer>entry=map.floorEntry(num);\n        while(entry!=null && entry.getValue()<=sum){\n            map.remove(entry.getKey());\n            int x=entry.getKey();\n            entry=map.floorEntry(x);\n        }\n        entry=map.ceilingEntry(num);\n        if(entry==null || entry.getValue()<sum)\n        map.put(num,sum);\n    }\n    public int queryVal(TreeMap<Integer,Integer>map,int num){\n        Map.Entry<Integer,Integer>entry=map.ceilingEntry(num);\n        if(entry==null) return -1;\n        return entry.getValue();\n    }\n    public int[] maximumSumQueries(int[] nums1, int[] nums2, int[][] queries) {\n        int n=nums1.length;\n        int m=queries.length;\n        List<int[]>v=new ArrayList<>();\n        for(int i=0;i<n;i++){\n            v.add(new int[]{nums1[i],nums2[i]});\n        }\n        Collections.sort(v,(a,b)->{\n            return a[0]-b[0];\n        });\n        List<Integer>ind=new ArrayList<>();\n        for(int i=0;i<m;i++) ind.add(i);\n        Collections.sort(ind,(a,b)->{\n            return queries[b][0]-queries[a][0];\n        });\n        TreeMap<Integer,Integer>values=new TreeMap<>();\n        int j=n-1;\n        int[]ans=new int[m];\n        for(int i:ind){\n            int a=queries[i][0];\n            int b=queries[i][1];\n            for(;j>=0 && v.get(j)[0]>=a;j--){\n                update(values,v.get(j)[1],v.get(j)[0]+v.get(j)[1]);\n            }\n            ans[i]=queryVal(values,b);\n        }\n        return ans;\n    }\n}\n```
['Sorting']