<p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> both of the same length. The <strong>advantage</strong> of <code>nums1</code> with respect to <code>nums2</code> is the number of indices <code>i</code> for which <code>nums1[i] &gt; nums2[i]</code>.</p>

<p>Return <em>any permutation of </em><code>nums1</code><em> that maximizes its <strong>advantage</strong> with respect to </em><code>nums2</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> nums1 = [2,7,11,15], nums2 = [1,10,4,11]
<strong>Output:</strong> [2,11,7,15]
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> nums1 = [12,24,8,32], nums2 = [13,25,32,11]
<strong>Output:</strong> [24,32,8,12]
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums1.length &lt;= 10<sup>5</sup></code></li>
	<li><code>nums2.length == nums1.length</code></li>
	<li><code>0 &lt;= nums1[i], nums2[i] &lt;= 10<sup>9</sup></code></li>
</ul>

class Solution {
public:
    vector<int> advantageCount(vector<int>& nums1, vector<int>& nums2) {
        return sol1(nums1, nums2);
    }

    vector<int> sol1(vector<int>& nums1, vector<int>& nums2) {
        int n = nums1.size();

        vector<pair<int, int>> nums2_indices(n);
        for (int i = 0; i < n; i++)
            nums2_indices[i] = {nums2[i], i};

        sort(nums2_indices.rbegin(), nums2_indices.rend());
        sort(nums1.rbegin(), nums1.rend());
        vector<int> ans(n);

        for(int i = 0, lp = 0, rp = n -1; i < n; i++){
            if(nums1[lp] > nums2_indices[i].first){
                ans[nums2_indices[i].second] = nums1[lp];
                lp++;
            }else{
                ans[nums2_indices[i].second] = nums1[rp];
                rp--;
            }
        }

        return ans;
    };

    vector<int> sol2(vector<int>& nums1, vector<int>& nums2) {
        multiset<int> mset(nums1.begin(), nums1.end());

        for (int i = 0; i < nums2.size(); i++) {
            int target = nums2[i];
            multiset<int>::iterator it = mset.upper_bound(target);
            it = it == mset.end() ? mset.begin() : it;
            nums1[i] = *it;
            mset.erase(it);
        }

        return nums1;
    };
};

/**
- Can reorder 1.
- Can't reorder 2.

How to do this?
I want to use the smallest number possible that allows me an advantage.


Feedback:
- You should be more active.
- Take more notes/be more systematic
- Use better names to avoid getting confused
- Estimate the complexity before answering the problem
- While problem solving, see if you can come up with more than one solution


I want to avoid using big nums for small numbers.


Approaches:
- Two sets


Psuedo code:
- for nums 2, create a copy of tuples
    - (val, index)

- for nums, create a mutli





===



https://leetcode.com/problems/advantage-shuffle/description//


newNums2 = [(num, i) for i, num in enumerate(nums2)]
newNums2.sort(reverse=true) # descending order

mset = multisett(nums1)
nums1 = [-1] * len(nums1)

for target, index in newNums2;
    biggerNum = find the smalles value in mset that's bigger than target.
    if biggerNum doesn't exit:
        continue
    nums1[index] = biggerNum

for i, num in nums1:
    if num != -1:
        continue
    nums[i] = mset.pop() # use an arbitrary number

return nums1





----
Sol1:

newNums2 = [(num, i) for i, num in enumerate(nums2)]
newNums2.sort(reverse=true) # descending order


nums1.sort(reverse=true)
lp,rp = 0, len(nums1) -1

ans = [-1] * len(nums1) // create the list
for num, index in newNums2:
    if nums[lp] > num:
        ans[index] = nums[lp] # winning number
        lp += 1
    else:
        ans[index] = nums[rp] # junk
        rp -= 1

return ans


Sol2:

mset = multiset(nums1)
for index, target in enumerate(nums2);
    biggerNum = find the smalles value in mset that's bigger than target.
    if biggerNum doesn't exit:
        nums1[index] = mset.pop() # pop smallest value in mset -- junk
    nums1[index] = biggerNum # winning number
    mset.pop(biggerNum)

return nums1



*/
65800