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<ii, 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:17:15: error: no match for 'operator[]' (operand types are 'std::map<std::pair<int, int>, std::vector<int> >' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'})
   17 |     sushi_list[t[i]].push_back(d[i]);
      |               ^
In file included from /usr/include/c++/14/map:63,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_map.h:504:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = std::pair<int, int>; _Tp = std::vector<int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, std::vector<int> > >; mapped_type = std::vector<int>; key_type = std::pair<int, int>]'
  504 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:504:34: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} to 'const std::map<std::pair<int, int>, std::vector<int> >::key_type&' {aka 'const std::pair<int, int>&'}
  504 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_map.h:524:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](key_type&&) [with _Key = std::pair<int, int>; _Tp = std::vector<int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, std::vector<int> > >; mapped_type = std::vector<int>; key_type = std::pair<int, int>]'
  524 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:524:29: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} to 'std::map<std::pair<int, int>, std::vector<int> >::key_type&&' {aka 'std::pair<int, int>&&'}
  524 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~
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;
      |                                         ^