Language: C++

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


int main(){
  int N,K;
  cin >>N>>K;
  vector<pair<ll, ll>> list;
  
  for (int i=0;i<N;i++){
    int t, d;
    cin >> t>> d;
    P p=make_pair(t,d);
    list.push_back(p);
  }

  //queue は，今使っている寿司番号を格納している。
  priority_queue<pair<ll, int>> que;
  //countは，答えに，何が何個使われているかをcountしている。
  map<ll, int> count;
  //初期化しておく
  for (int i=0;i<N;i++){
    count[list[i][0]]=0;
  }
  
  ll bonus=0;
  ll delicious=0;

  //はじめの状態
  for (int i=0;i<K;i++){
    delicious+=list[i][1];
    P r=make_pair(list[i][1], i);
    que.push(r);
    count[list[i][0]]++;
    if (count[list[i][0]==1){
      bonus++;
    }
  }

  ll ans=pow(bonus, 2)+delicious;

  for (int i=K;i<N;i++){
    if (count[list[i+1][0]]==0){
      P r=que.top();
      int k=r.second
      int ans_2=pow(bonus+1, 2)+delicious-list[k][1]+list[i][1];
      if (ans_2>ans){
        count[list[i][0]]++;
        r=make_pair(list[i][1], i);
        que.pop();que.push(r);
        bonus++;
        delicious+=list[i][1]-list[k][1];
        count[list[k][0]]--;
        ans=pow(bonus, 2)+delicious;
      }
    }
  cout << ans;
  return 0;
  }
  



Compiler output:
a.cc: In function 'int main()':
a.cc:30:18: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'std::pair<long long int, long long int>'} and 'int')
   30 |     count[list[i][0]]=0;
      |                  ^
a.cc:38:23: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'std::pair<long long int, long long int>'} and 'int')
   38 |     delicious+=list[i][1];
      |                       ^
a.cc:39:26: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'std::pair<long long int, long long int>'} and 'int')
   39 |     P r=make_pair(list[i][1], i);
      |                          ^
a.cc:41:18: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'std::pair<long long int, long long int>'} and 'int')
   41 |     count[list[i][0]]++;
      |                  ^
a.cc:42:22: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'std::pair<long long int, long long int>'} and 'int')
   42 |     if (count[list[i][0]==1){
      |                      ^
a.cc:42:28: error: expected ']' before ')' token
   42 |     if (count[list[i][0]==1){
      |                            ^
      |                            ]
a.cc:50:24: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'std::pair<long long int, long long int>'} and 'int')
   50 |     if (count[list[i+1][0]]==0){
      |                        ^
a.cc:53:7: error: expected ',' or ';' before 'int'
   53 |       int ans_2=pow(bonus+1, 2)+delicious-list[k][1]+list[i][1];
      |       ^~~
a.cc:54:11: error: 'ans_2' was not declared in this scope; did you mean 'ans'?
   54 |       if (ans_2>ans){
      |           ^~~~~
      |           ans
a.cc:55:22: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'std::pair<long long int, long long int>'} and 'int')
   55 |         count[list[i][0]]++;
      |                      ^
a.cc:56:28: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'std::pair<long long int, long long int>'} and 'int')
   56 |         r=make_pair(list[i][1], i);
      |                            ^
a.cc:59:27: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'std::pair<long long int, long long int>'} and 'int')
   59 |         delicious+=list[i][1]-list[k][1];
      |                           ^
a.cc:59:38: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'std::pair<long long int, long long int>'} and 'int')
   59 |         delicious+=list[i][1]-list[k][1];
      |                                      ^
a.cc:60:22: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'std::pair<long long int, long long int>'} and 'int')
   60 |         count[list[k][0]]--;
      |                      ^
a.cc:66:4: error: expected '}' at end of input
   66 |   }
      |    ^
a.cc:12:11: note: to match this '{'
   12 | int main(){
      |           ^