Language: C++

#include <iostream>
#include <fstream>
#include <algorithm>       // for next_permutation
#include <vector>
#include <bits/stl_numeric.h>

#define DEBUG 0
#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
typedef pair<int, int> pii;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;


ll N, K;
int main() {

    cin >> N >> K;

    //種類が何個あるか
    vector <int> v[N];
    //ネタ
    vector <ll> t(N);
    //おいしさ
    vector <ll> d(N);
    vector <pii> p(N);
    REP(i,N)
    {
        cin >> t[i] >> d[i];
        --t[i];
        p.push_back(pii(d[i], t[i]));
    }
    //美味しさの順でソートする
    sort(p.begin(),p.end(), greater<pii>());

    ll res = 0;
    priority_queue <pii, vector<pii>, greater<pii>> que;
    ll cnt = 0;

    for(int i = 0; i < K; ++i)
    {
        if(v[p[i].second].size() == 0)
        {
            ++cnt;
        }
        else
        {
            //入れ替える可能性のあるものをqueに突っ込んどく(queは昇順ソートされている)
            que.push(p[i]);
        }
        res += p[i].first;
        v[p[i].second].push_back(p[i].first);
    } 

    res += (ll)cnt * cnt;
    ll out = res;
    int cur = K;
    for(; cur < N; ++cur)
    {
        if(que.empty())break;
        int idx = p[cur].second;
        if(v[idx].size() == 0)
        {
            pii top = que.top();
            que.pop();
            v[idx].push_back(p[cur].first);
            ++cnt;
            res += 2 * cnt - 1;
            res -= top.first;
            res += p[cur].first;
            //入れ替えて種類を増やしたときの値を求める
            out = max(res, out);
        }
    }


    cout << out << endl;
    return 0;
}


Compiler output:
a.cc:10:9: error: 'pair' does not name a type
   10 | typedef pair<int, int> pii;
      |         ^~~~
a.cc: In function 'int main()':
a.cc:27:13: error: 'pii' was not declared in this scope
   27 |     vector <pii> p(N);
      |             ^~~
a.cc:27:16: error: template argument 1 is invalid
   27 |     vector <pii> p(N);
      |                ^
a.cc:27:16: error: template argument 2 is invalid
a.cc:32:11: error: request for member 'push_back' in 'p', which is of non-class type 'int'
   32 |         p.push_back(pii(d[i], t[i]));
      |           ^~~~~~~~~
a.cc:35:12: error: request for member 'begin' in 'p', which is of non-class type 'int'
   35 |     sort(p.begin(),p.end(), greater<pii>());
      |            ^~~~~
a.cc:35:22: error: request for member 'end' in 'p', which is of non-class type 'int'
   35 |     sort(p.begin(),p.end(), greater<pii>());
      |                      ^~~
a.cc:38:5: error: 'priority_queue' was not declared in this scope
   38 |     priority_queue <pii, vector<pii>, greater<pii>> que;
      |     ^~~~~~~~~~~~~~
a.cc:6:1: note: 'std::priority_queue' is defined in header '<queue>'; this is probably fixable by adding '#include <queue>'
    5 | #include <bits/stl_numeric.h>
  +++ |+#include <queue>
    6 | 
a.cc:38:36: error: template argument 2 is invalid
   38 |     priority_queue <pii, vector<pii>, greater<pii>> que;
      |                                    ^
a.cc:38:53: error: 'que' was not declared in this scope
   38 |     priority_queue <pii, vector<pii>, greater<pii>> que;
      |                                                     ^~~
a.cc:43:15: error: invalid types 'int[int]' for array subscript
   43 |         if(v[p[i].second].size() == 0)
      |               ^
a.cc:50:23: error: invalid types 'int[int]' for array subscript
   50 |             que.push(p[i]);
      |                       ^
a.cc:52:17: error: invalid types 'int[int]' for array subscript
   52 |         res += p[i].first;
      |                 ^
a.cc:53:12: error: invalid types 'int[int]' for array subscript
   53 |         v[p[i].second].push_back(p[i].first);
      |            ^
a.cc:53:35: error: invalid types 'int[int]' for array subscript
   53 |         v[p[i].second].push_back(p[i].first);
      |                                   ^
a.cc:62:20: error: invalid types 'int[int]' for array subscript
   62 |         int idx = p[cur].second;
      |                    ^
a.cc:65:16: error: expected ';' before 'top'
   65 |             pii top = que.top();
      |                ^~~~
      |                ;
a.cc:67:31: error: invalid types 'int[int]' for array subscript
   67 |             v[idx].push_back(p[cur].first);
      |                               ^
a.cc:70:20: error: 'top' was not declared in this scope
   70 |             res -= top.first;
      |                    ^~~
a.cc:71:21: error: invalid types 'int[int]' for array subscript
   71 |             res += p[cur].first;
      |                     ^