Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ll> vll;


ll solve(int N, int K, vi& t, vi& d){
  //sushi_listを作る.各tiに対して、その美味しさリストを対応させる。
  map<i, vi> sushi_list;
  for (int i=0;i<N;i++){
    sushi_list[t[i]].push_back(d[i]);
  }

  //各種類の美味しさmaxの奴ら（head)と、それ以外(tail)に分ける。
  vi head, tail;
  for (auto p: sushi_list){
    vi q=p.second;
    sort(q.begin(), q.end());
    head.push_back(q.back());
    q.pop_back();
    tail.insert(tail.end(), q.begin(),q.end());
  }

  //head, tailの累積和を計算
  int H=head.size();
  int T=tail.size();
  ll head_cum(H+1);
  ll tail_cum(T+1);
  head_cum[0]=0;
  tail_cum[0]=0;
  for (int i=0;i<H;i++){
    head_cum[i+1]=head_cum[i]+head[i+1];
  }
  for (int i=0;i<T;i++){
    tail_cum[i+1]=tail_cum[i]+tail[i+1]
  }

  //ansを計算
  ll best=0;
  for (int n_unique=1;n_unique<=T;n_unique++){
    if((n_unique<=K)&&(K-n_unique<=H)){
      ll tmp=head_cum[n_unique]+tail_cum[K-n_unique]+(ll)n_unique*n_unique;
      best=max(best, tmp);
    }
  }
  return best;
}

int main(){
  int N, K;scanf("%d%d", &N, &K);
  vi t(N), d(N);
  for (int i=0;i<N;i++){
    scanf("%d%d", &t[i], &d[i]);
    cout << solve(N, K, t, d);
    return 0;
  }
}


Compiler output:
a.cc: In function 'll solve(int, int, vi&, vi&)':
a.cc:15:7: error: 'i' was not declared in this scope
   15 |   map<i, vi> sushi_list;
      |       ^
a.cc:15:12: error: template argument 1 is invalid
   15 |   map<i, vi> sushi_list;
      |            ^
a.cc:15:12: error: template argument 3 is invalid
a.cc:15:12: error: template argument 4 is invalid
a.cc:17:15: error: invalid types 'int[__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}]' for array subscript
   17 |     sushi_list[t[i]].push_back(d[i]);
      |               ^
a.cc:22:16: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
   22 |   for (auto p: sushi_list){
      |                ^~~~~~~~~~
      |                std::begin
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:114:37: note: 'std::begin' declared here
  114 |   template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept;
      |                                     ^~~~~
a.cc:22:16: error: 'end' was not declared in this scope; did you mean 'std::end'?
   22 |   for (auto p: sushi_list){
      |                ^~~~~~~~~~
      |                std::end
/usr/include/c++/14/bits/range_access.h:116:37: note: 'std::end' declared here
  116 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
      |                                     ^~~
a.cc:35:11: error: invalid types 'll {aka long long int}[int]' for array subscript
   35 |   head_cum[0]=0;
      |           ^
a.cc:36:11: error: invalid types 'll {aka long long int}[int]' for array subscript
   36 |   tail_cum[0]=0;
      |           ^
a.cc:38:13: error: invalid types 'll {aka long long int}[int]' for array subscript
   38 |     head_cum[i+1]=head_cum[i]+head[i+1];
      |             ^
a.cc:38:27: error: invalid types 'll {aka long long int}[int]' for array subscript
   38 |     head_cum[i+1]=head_cum[i]+head[i+1];
      |                           ^
a.cc:41:13: error: invalid types 'll {aka long long int}[int]' for array subscript
   41 |     tail_cum[i+1]=tail_cum[i]+tail[i+1]
      |             ^
a.cc:41:27: error: invalid types 'll {aka long long int}[int]' for array subscript
   41 |     tail_cum[i+1]=tail_cum[i]+tail[i+1]
      |                           ^
a.cc:48:22: error: invalid types 'll {aka long long int}[int]' for array subscript
   48 |       ll tmp=head_cum[n_unique]+tail_cum[K-n_unique]+(ll)n_unique*n_unique;
      |                      ^
a.cc:48:41: error: invalid types 'll {aka long long int}[int]' for array subscript
   48 |       ll tmp=head_cum[n_unique]+tail_cum[K-n_unique]+(ll)n_unique*n_unique;
      |                                         ^