O(nq) but beats 66%
not optimal O(nq), nevertheless beats ~ 66%\n- sort and remove all dominated (no contribution to final result) ones\n- for each query, binary search twices to f
- not optimal `O(nq)`, nevertheless beats ~ `66%`\n- `sort` and remove all `dominated` (no contribution to final result) ones\n- for each query, `binary search` twices to find qualified candidates, before a simple `linear search` to find the maximal contributor\n```\nclass Solution {\npublic:\n    vector<int> maximumSumQueries(vector<int>& nums1, vector<int>& nums2, vector<vector<int>>& queries) {\n        int n = nums1.size();\n        vector<pair<int,int>> pairs0(n);\n        for(int i = 0; i < n; ++i) \n            pairs0[i] = {nums1[i], nums2[i]};\n        sort(pairs0.begin(), pairs0.end());\n        \n        //remove all dominated pairs in pairs0: (a2, b2) dominates (a1, b1) iff a2 >= a1 and b2 >= b1\n        vector<pair<int,int>> pairs(1, pairs0[0]);\n        for(int i = 0; i < n; ++i) {\n            while(!pairs.empty() && pairs0[i].second >= pairs.back().second) {\n                pairs.pop_back();\n            }\n            pairs.push_back(move(pairs0[i]));\n        }\n        // now we have (a,b) in parirs, where component a is increasing and b is decreasing.\n        // so for each query, we binary search twice to find the contribution pairs, and then linear search maximum\n        vector<int> ans;\n        for(auto const& q : queries) {\n            int x = q[0], y = q[1];\n            auto b = pairs.begin(), e = pairs.end();\n            auto i = lower_bound(b, e, pair(x,y), [](auto const& p1, auto const& p2) { return p1.first < p2.first; });\n            auto j = upper_bound(i, e, pair(x,y), [](auto const& p1, auto const& p2) { return p1.second > p2.second; });\n            auto k = max_element(i, j, [](auto & p1, auto & p2) { return p1.first + p1.second < p2.first + p2.second; });\n            ans.push_back(k == j ? -1 : k->first + k->second);\n        }\n        return ans;\n    }\n};\n```
['C++']