Language: C++

# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n, k;
LL t[101010], d[101010];
LL cnt[101010];
LL x;
vector<pair<LL, LL>> v;

int main(){
    cin >> n >> k;
    REP(i, n){
        cin >> t[i] >> d[i];
        v.emplace_back(make_pair(d[i], t[i]));
    }
    sort(ALL(v));
    reverse(ALL(v));
    priority_queue<pair<LL, llogbf32x>, vector<pair<LL, llogbf32x>>, greater<pair<LL, llogbf32x>>> pq;
    LL ans = 0, sum = 0;
    REP(i, k){
        pq.push(v[i]);
        sum += v[i].first;
        cnt[v[i].second]++;
        if(cnt[v[i].second] == 1)x++;
    }
    ans = sum + x*x;
    for(int i = k;i < n;i++){
        if(cnt[v[i].second])continue;
        LL num = -1;
        while(!pq.empty()){
            auto p = pq.top();
            pq.pop();
            if(cnt[p.second] >= 2){
                cnt[p.second]--;
                num = p.first;
                break;
            }
        }
        if(num == -1)break;
        x++;
        cnt[v[i].second]++;
        sum += v[i].first;
        sum -= num;
        ans = max(ans, sum + x*x);
    }
    cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:40:38: error: type/value mismatch at argument 2 in template parameter list for 'template<class _T1, class _T2> struct std::pair'
   40 |     priority_queue<pair<LL, llogbf32x>, vector<pair<LL, llogbf32x>>, greater<pair<LL, llogbf32x>>> pq;
      |                                      ^
a.cc:40:38: note:   expected a type, got 'llogbf32x'
a.cc:40:57: error: type/value mismatch at argument 2 in template parameter list for 'template<class _T1, class _T2> struct std::pair'
   40 |     priority_queue<pair<LL, llogbf32x>, vector<pair<LL, llogbf32x>>, greater<pair<LL, llogbf32x>>> pq;
      |                                                         ^~~~~~~~~
a.cc:40:57: note:   expected a type, got 'llogbf32x'
a.cc:40:66: error: template argument 1 is invalid
   40 |     priority_queue<pair<LL, llogbf32x>, vector<pair<LL, llogbf32x>>, greater<pair<LL, llogbf32x>>> pq;
      |                                                                  ^~
a.cc:40:66: error: template argument 2 is invalid
a.cc:40:87: error: type/value mismatch at argument 2 in template parameter list for 'template<class _T1, class _T2> struct std::pair'
   40 |     priority_queue<pair<LL, llogbf32x>, vector<pair<LL, llogbf32x>>, greater<pair<LL, llogbf32x>>> pq;
      |                                                                                       ^~~~~~~~~
a.cc:40:87: note:   expected a type, got 'llogbf32x'
a.cc:40:96: error: template argument 1 is invalid
   40 |     priority_queue<pair<LL, llogbf32x>, vector<pair<LL, llogbf32x>>, greater<pair<LL, llogbf32x>>> pq;
      |                                                                                                ^~
a.cc:40:98: error: template argument 1 is invalid
   40 |     priority_queue<pair<LL, llogbf32x>, vector<pair<LL, llogbf32x>>, greater<pair<LL, llogbf32x>>> pq;
      |                                                                                                  ^
a.cc:40:98: error: template argument 2 is invalid
a.cc:40:98: error: template argument 3 is invalid
a.cc:43:12: error: request for member 'push' in 'pq', which is of non-class type 'int'
   43 |         pq.push(v[i]);
      |            ^~~~
a.cc:52:19: error: request for member 'empty' in 'pq', which is of non-class type 'int'
   52 |         while(!pq.empty()){
      |                   ^~~~~
a.cc:53:25: error: request for member 'top' in 'pq', which is of non-class type 'int'
   53 |             auto p = pq.top();
      |                         ^~~
a.cc:54:16: error: request for member 'pop' in 'pq', which is of non-class type 'int'
   54 |             pq.pop();
      |                ^~~