Submission

Status:

(PPPPPPPTSSSSSS)(PPPPPPPPPPP)(PPPPPPPPP)(PPTSSSSSSS)(PPTSSSSSSS)(PPPPPPPPTSSSSS)(TSSSSSSSSSSSSSSSSSSSSS)

Subtask/Task Score:

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

Score: 15

User: hyyh

Problemset: แคง (Kang)

Language: cpp

Time: 2.107 second

Submitted On: 2026-03-14 20:50:09

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pii = pair<ll,ll>;

#define m_p make_pair

#define f first
#define s second

std::vector<long long> capsize(std::vector<int> A, std::vector<int> B) {
  multiset<pii,greater<pii>> ms;
  map<ll,ll> mp;
  vector<ll> answer;
  map<ll,bool> used;
  ll cur = 0;
  ll sum = 0;
  for(auto k:A){
    if(mp.count(k)) mp[k]++;
    else mp[k] = 1;
  }
  for(auto [a,b]:mp){
    ms.insert(m_p(a*b,a));
    sum += a*b;
  }
  for(auto k:B){
    bool us = used[k];
    sum += k;
    if(mp.count(k)){
      if(!us){
        ms.erase(ms.find(m_p(mp[k]*k,k)));
        mp[k]++;
        ms.insert(m_p(mp[k]*k,k));
      }
      else{
        mp[k]++;
        cur += k;
      }
    }
    else{
      mp[k] = 1;
      ms.insert(m_p(k,k));
    }
    auto it = ms.begin();
    cur += it->f;
    used[it->s] = 1;
    ms.erase(it);
    answer.emplace_back(sum-cur);
  }
  return answer;
}