Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class Sushi{
    public:
        Sushi(int t = 0, int d = 0){
            kind = t;
            taste = d;
        }
        int kind;
        long taste;
};
void removeTop(vector<long>& heap){
    heap[0] = heap[heap.size() - 1];
    heap.pop_back();
    int i = 0;
    int n = heap.size() - 1;
    int max;
    while(2 * i + 1 <= n){ // 左の子が存在する
        if(heap[i] < heap[2 * i + 1]){ // 左の子のほうが大きい
            long temp = heap[i];
            if(2 * i + 2 <= n && heap[2 * i + 1] < heap[2 * i + 2]){ // 右の子が存在し、右の子のほうがより大きい
                heap[i] = heap[2 * i + 2];
                heap[2 * i + 2] = temp;
                i = 2 * i + 2;
            }
            else{ // 右の子が存在しないか、左の子のほうがより大きい
                heap[i] = heap[2 * i + 1];
                heap[2 * i + 1] = temp;
                i = 2 * i + 1;
            }
        }
        else if(2 * i + 2 <= n && heap[2 * i + 1] < heap[2 * i + 2]){ // 右の子が存在し、右の子のほうが大きい
            long temp = heap[i];
            heap[i] = heap[2 * i + 2];
            heap[2 * i + 2] = temp;
            i = 2 * i + 2;
        }
        else{
            break;
        }
    }
}
int main(void)
{
    bool debug = false;
    int N, K;
    cin >> N >> K;
    Sushi list[100000] = {};
    int t, d;
    for(int i = 0; i < N; i++){
        cin >> t >> d;
        list[i] = Sushi(t, d);
    }
    vector<vector<long>> eat(N);
    vector<vector<long>> not(N);
    sort(list, list+100000, [](const Sushi& x, const Sushi& y){return x.taste > y.taste;});
    long long result = 0;
    int kind = 0;
    Sushi loop;
    for(int i = 0; i < N; i++){
        loop = list[i];
        if(i < K){
            eat[loop.kind - 1].push_back(loop.taste);
            result += loop.taste;
            if(eat[loop.kind - 1].size() == 1){
                kind++;
            }
        }
        else{
            not[loop.kind - 1].push_back(loop.taste);
        }
    }
    result += kind * kind;
    long long temp = result;
    int min_index;
    long min;
    int max_index;
    long max;
    for(int i = kind + 1; i < N; i++){
        min = LONG_MAX;
        max = LONG_MIN;
        for(int j = 0; j < N; j++){ 
            if(eat[j].size() > 1 && min > eat[j][eat[j].size() - 1]){
                min_index = j;
                min = eat[j][eat[j].size() - 1];
            }
            else if(eat[j].size() == 0 && not[j].size() > 0 && max < not[j][0]){
                max_index = j;
                max = not[j][0];
            }
        }
        if(max == LONG_MIN){
            break;
        }
        temp += max - min;
        temp += (kind + 1) * (kind + 1) - kind * kind;
        eat[min_index].pop_back();
        eat[max_index].push_back(max);
        removeTop(not[max_index]);
        kind++;
        if(temp > result){
            result = temp;
        }
    }
    cout << result << "\n";
}

Compiler output:
a.cc: In function 'int main()':
a.cc:57:26: error: expected unqualified-id before 'not' token
   57 |     vector<vector<long>> not(N);
      |                          ^~~
a.cc:72:21: error: expected ',' before '.' token
   72 |             not[loop.kind - 1].push_back(loop.taste);
      |                     ^
      |                     ,
a.cc:72:21: error: expected identifier before '.' token
a.cc: In lambda function:
a.cc:72:31: error: expected '{' before '.' token
   72 |             not[loop.kind - 1].push_back(loop.taste);
      |                               ^
a.cc: In function 'int main()':
a.cc:72:32: error: 'struct main()::<lambda()>' has no member named 'push_back'
   72 |             not[loop.kind - 1].push_back(loop.taste);
      |                                ^~~~~~~~~
a.cc:82:15: error: 'LONG_MAX' was not declared in this scope
   82 |         min = LONG_MAX;
      |               ^~~~~~~~
a.cc:4:1: note: 'LONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    3 | #include <algorithm>
  +++ |+#include <climits>
    4 | using namespace std;
a.cc:83:15: error: 'LONG_MIN' was not declared in this scope
   83 |         max = LONG_MIN;
      |               ^~~~~~~~
a.cc:83:15: note: 'LONG_MIN' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
a.cc: In lambda function:
a.cc:89:49: error: expected '{' before '.' token
   89 |             else if(eat[j].size() == 0 && not[j].size() > 0 && max < not[j][0]){
      |                                                 ^
a.cc: In function 'int main()':
a.cc:89:50: error: 'struct main()::<lambda()>' has no member named 'size'
   89 |             else if(eat[j].size() == 0 && not[j].size() > 0 && max < not[j][0]){
      |                                                  ^~~~
a.cc: In lambda function:
a.cc:89:76: error: expected '{' before '[' token
   89 |             else if(eat[j].size() == 0 && not[j].size() > 0 && max < not[j][0]){
      |                                                                            ^
a.cc: In function 'int main()':
a.cc:89:76: error: no match for 'operator[]' (operand types are 'main()::<lambda()>' and 'int')
a.cc: In lambda function:
a.cc:91:29: error: expected '{' before '[' token
   91 |                 max = not[j][0];
      |                             ^
a.cc: In function 'int main()':
a.cc:91:29: error: no match for 'operator[]' (operand types are 'main()::<lambda()>' and 'int')
a.cc: In lambda function:
a.cc:101:33: error: expected '{' before ')' token
  101 |         removeTop(not[max_index]);
      |                                 ^
a.cc: In function 'int main()':
a.cc:101:19: error: no match for 'operator!' (operand type is 'main()::<lambda()>')
  101 |         removeTop(not[max_index]);
      |                   ^~~~~~~~~~~~~~
a.cc:101:19: note: candidate: 'operator!(bool)' (built-in)
a.cc:101:19: note:   no known conversion for argument 1 from 'main()::<lambda()>' to 'bool'