Skip to content

Latest commit

 

History

History
28 lines (20 loc) · 659 Bytes

870.-advantage-shuffle.md

File metadata and controls

28 lines (20 loc) · 659 Bytes

870. Advantage Shuffle

class Solution:
    def advantageCount(self, A: List[int], B: List[int]) -> List[int]:
        
        numsb = [(e,i) for i,e in enumerate(B)]
        
        from sortedcontainers import SortedList
        sd = SortedList(A)

        print(sd)
        ans = [-1] * len(A)
        for v,i in sorted(numsb,reverse = True):
            
            idx = sd.bisect_right(v)
            # print(idx)
            if idx < len(sd):
                ans[i] = sd[idx]
                sd.pop(index=idx)
            else:
                ans[i] = sd[0]
                sd.pop(index=0)
            
        return ans