Submission

Status:

(PPPPPPPPPPPPPP)(PPPPPPPPPPP)(PPPPPPPPP)(PPPPPPPPPP)(PPPPPPPPPP)(PPPPPPPPPPPPPP)(TSSSSSSSSSSSSSSSSSSSSS)

Subtask/Task Score:

{5/5}{7/7}{8/8}{12/12}{16/16}{28/28}{0/24}

Score: 76

User: 12345678

Problemset: แคง (Kang)

Language: cpp

Time: 2.103 second

Submitted On: 2026-02-28 22:05:00

#include <bits/stdc++.h>

using namespace std;

#define ll long long

std::vector<long long> capsize(std::vector<int> A, std::vector<int> B) {
    int n=A.size(), m=B.size();
    vector<ll> res;
    ll sm=0;
    priority_queue<pair<ll, ll>> pq;
    set<ll> used;
    map<ll, ll> mp;
    for (int i=0; i<n; i++) sm+=A[i], mp[A[i]]++;
    for (auto [x, y]:mp) pq.push({x*y, x});
    for (int i=0; i<m; i++)
    {
        if (used.find(B[i])==used.end()) mp[B[i]]++, pq.push({B[i]*mp[B[i]], B[i]}), sm+=B[i];
        while (!pq.empty()) 
        {
            auto [cst, vl]=pq.top();
            pq.pop();
            if (used.find(vl)!=used.end()) continue;
            sm-=cst;
            used.insert(vl);
            break;
        }
        res.push_back(sm);
    }        
    return res;
}