Language: C++

#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>
typedef long long ll;
using namespace std;


int main(){
  //recieve input
  int N, K;cin >> N>>K;
  vector<pair<int, int>> sushi_list;
  for (int n=0;n<N;n++){
    int t, d; cin >> t>>d;
    pair<int, int> p=make_pair(d,t);
    sushi_list.push_back(p);
  }

  //sort sushi_list based on tast.
  sort(sushi_list.begin(), sushi_list.end(), greater<pair<int, int>>());

  //compute the initial score
  ll raw_score=0;
  //list of items that can be changed
  priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> rem_list;
  //used sushis
  map<int, int> used;

  for (int k=0;k<K;k++){
    pair<int, int> p=sushi_list[k];
    int d=p.first;
    int t=p.second;

    raw_score+=d;
    used[t]++;
    rem_list.push(p);
  }

  //compute best score
  ll best_score=raw_score+used.size()*used.size();
  for (int k=K;k<N;k++){
    int p=sushi_list[k];
    int d=p.first;
    int t=p.second;

    while(!rem_list.empty()){
      pair<int, int> q=rem_list.top();
      int d_=q.first;
      int t_=q.second;
      if (used[t_]==1){
        rem_list.pop();
        continue;
      }
      break;
    }
    if (rem_list.empty()){
      break;
    }

    pair<int, int> q=rem_list.top();
    int d_=q.first;
    int t_=q.second;

    used[t]++;
    used[t_]--;
    raw_score+=d-d_;
    rem_list.pop();
    best_score=max(best_score, raw_score+used.size()*used.size());
  }

  cout << best_score;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:43:23: error: cannot convert '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} to 'int' in initialization
   43 |     int p=sushi_list[k];
      |                       ^
a.cc:44:13: error: request for member 'first' in 'p', which is of non-class type 'int'
   44 |     int d=p.first;
      |             ^~~~~
a.cc:45:13: error: request for member 'second' in 'p', which is of non-class type 'int'
   45 |     int t=p.second;
      |             ^~~~~~
a.cc:69:19: error: no matching function for call to 'max(ll&, long long unsigned int)'
   69 |     best_score=max(best_score, raw_score+used.size()*used.size());
      |                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 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/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:69:19: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
   69 |     best_score=max(best_score, raw_score+used.size()*used.size());
      |                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:69:19: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   69 |     best_score=max(best_score, raw_score+used.size()*used.size());
      |                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~