https://leetcode.com/problems/largest-values-from-labels/

typedef struct item{
    int value, label;
}Item;
 
bool cmp(Item& i1, Item& i2){
    return i1.value > i2.value;
}
 
class Solution {
public:
    int largestValsFromLabels(vector<int>& values, vector<int>& labels, int num_wanted, int use_limit) {
        int idx, sum = 0;
        map<int, int> count;
        vector<Item> items;
        //kek
 
        if(!(values.size() && values.size() == labels.size()) || !use_limit) return 0;
 
        for(idx = 0;idx < values.size();idx++)
            items.push_back({values[idx], labels[idx]});
 
        sort(items.begin(), items.end(), cmp);
 
        for(idx = 0;idx < items.size() && num_wanted;idx++){
            if(count.find(items[idx].label) == count.end() || 
               count[items[idx].label] < use_limit){
                count[items[idx].label]++;
                sum += items[idx].value;
                num_wanted--;
            }
        }
 
        return sum;
    }
};