Language: C++

#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>
typedef long long ll;
typedef pair<int, int> ii;
using namespace;


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

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

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

  for (int k=0;k<K;k++){
    ii 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()){
      ii 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;
    }

    ii 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:7:9: error: 'pair' does not name a type
    7 | typedef pair<int, int> ii;
      |         ^~~~
a.cc:8:16: error: expected identifier before ';' token
    8 | using namespace;
      |                ^
a.cc: In function 'int main()':
a.cc:13:12: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   13 |   int N, K;cin >> N>>K;
      |            ^~~
      |            std::cin
In file included from a.cc:1:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:14:3: error: 'vector' was not declared in this scope
   14 |   vector<ii> sushi_list;
      |   ^~~~~~
a.cc:14:3: note: suggested alternatives:
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/queue:63,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_vector.h:428:11: note:   'std::vector'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
/usr/include/c++/14/vector:93:13: note:   'std::pmr::vector'
   93 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
a.cc:14:10: error: 'ii' was not declared in this scope
   14 |   vector<ii> sushi_list;
      |          ^~
a.cc:14:14: error: 'sushi_list' was not declared in this scope
   14 |   vector<ii> sushi_list;
      |              ^~~~~~~~~~
a.cc:17:7: error: expected ';' before 'p'
   17 |     ii p=make_pair(d,t);
      |       ^~
      |       ;
a.cc:18:26: error: 'p' was not declared in this scope
   18 |     sushi_list.push_back(p);
      |                          ^
a.cc:22:46: error: 'greater' was not declared in this scope; did you mean 'std::greater'?
   22 |   sort(sushi_list.begin(), sushi_list.end(), greater<ii>());
      |                                              ^~~~~~~
      |                                              std::greater
In file included from /usr/include/c++/14/string:49,
                 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:
/usr/include/c++/14/bits/stl_function.h:353:12: note: 'std::greater' declared here
  353 |     struct greater;
      |            ^~~~~~~
a.cc:22:58: error: expected primary-expression before ')' token
   22 |   sort(sushi_list.begin(), sushi_list.end(), greater<ii>());
      |                                                          ^
a.cc:22:3: error: 'sort' was not declared in this scope; did you mean 'std::sort'?
   22 |   sort(sushi_list.begin(), sushi_list.end(), greater<ii>());
      |   ^~~~
      |   std::sort
In file included from /usr/include/c++/14/algorithm:86,
                 from a.cc:4:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:296:1: note: 'std::sort' declared here
  296 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last);
      | ^~~~
a.cc:27:3: error: 'priority_queue' was not declared in this scope; did you mean 'std::priority_queue'?
   27 |   priority_queue<ii, vector<ii>, greater<ii>> rem_list;
      |   ^~~~~~~~~~~~~~
      |   std::priority_queue
In file included from /usr/include/c++/14/queue:66:
/usr/include/c++/14/bits/stl_queue.h:496:11: note: 'std::priority_queue' declared here
  496 |     class priority_queue
      |           ^~~~~~~~~~~~~~
a.cc:27:32: error: expected primary-expression before ',' token
   27 |   priority_queue<ii, vector<ii>, greater<ii>> rem_list;
      |                                ^
a.cc:27:47: error: 'rem_list' was not declared in this scope
   27 |   priority_queue<ii, vector<ii>, greater<ii>> rem_list;
      |                                               ^~~~~~~~
a.cc:29:3: error: 'map' was not declared in this scope
   29 |   map<int, int> used;
      |   ^~~
a.cc:29:3: note: suggested alternatives:
In file included from /usr/include/c++/14/map:63,
                 from a.cc:5:
/usr/include/c++/14/bits/stl_map.h:102:11: note:   'std::map'
  102 |     class map
      |           ^~~
/usr/include/c++/14/map:89:13: note:   'std::pmr::map'
   89 |       using map
      |             ^~~
a.cc:29:7: error: expected primary-expression before 'int'
   29 |   map<int, int> used;
      |       ^~~
a.cc:32:7: error: expected ';' before 'p'
   32 |     ii p=sushi_list[k];
      |       ^~
      |       ;
a.cc:33:11: error: 'p' was not declared in this scope
   33 |     int d=p.first;
      |           ^
a.cc:37:5: error: 'used' was not declared in this scope
   37 |     used[t]++;
      |     ^~~~
a.cc:42:27: error: 'used' was not declared in this scope
   42 |   ll best_score=raw_score+used.size()*used.size();
      |                           ^~~~
a.cc:45:13: error: request for member 'first' in 'p', which is of non-class type 'int'
   45 |     int d=p.first;
      |             ^~~~~
a.cc:46:13: error: request for member 'second' in 'p', which is of non-class type 'int'
   46 |     int t=p.second;
      |             ^~~~~~
a.cc:49:9: error: expected ';' before 'q'
   49 |       ii q=rem_list.top();
      |         ^~
      |         ;
a.cc:50:14: error: 'q' was not declared in this scope
   50 |       int d_=q.first;
      |              ^
a.cc:62:7: error: expected ';' before 'q'
   62 |     ii q=rem_list.top();
      |       ^~
      |       ;
a.cc:63:12: error: 'q' was not declared in this scope
   63 |     int d_=q.first;
      |            ^
a.cc:70:16: error: 'max' was not declared in this scope; did you mean 'std::max'?
   70 |     best_score=max(best_score, raw_score+used.size()*used.size());
      |                ^~~
      |                std::max
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: 'std::max' declared here
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
a.cc:73:3: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   73 |   cout << best_score;
      |   ^~~~
      |   std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~