Language: C++

#include<iostream>
#include<queue>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
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]].first=0;
  }
  
  ll bonus=0;
  ll delicious=0;

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

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

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


Compiler output:
a.cc: In function 'int main()':
a.cc:30:10: error: no match for 'operator[]' (operand types are 'std::map<long long int, int>' and '__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>'})
   30 |     count[list[i]].first=0;
      |          ^
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 = long long int; _Tp = int; _Compare = std::less<long long int>; _Alloc = std::allocator<std::pair<const long long int, int> >; mapped_type = int; key_type = long long 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<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>'} to 'const std::map<long long int, int>::key_type&' {aka 'const long long 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 = long long int; _Tp = int; _Compare = std::less<long long int>; _Alloc = std::allocator<std::pair<const long long int, int> >; mapped_type = int; key_type = long long 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<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>'} to 'std::map<long long int, int>::key_type&&' {aka 'long long int&&'}
  524 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~
a.cc:41:10: error: no match for 'operator[]' (operand types are 'std::map<long long int, int>' and '__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>'})
   41 |     count[list[i]].first++;
      |          ^
/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 = long long int; _Tp = int; _Compare = std::less<long long int>; _Alloc = std::allocator<std::pair<const long long int, int> >; mapped_type = int; key_type = long long 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<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>'} to 'const std::map<long long int, int>::key_type&' {aka 'const long long 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 = long long int; _Tp = int; _Compare = std::less<long long int>; _Alloc = std::allocator<std::pair<const long long int, int> >; mapped_type = int; key_type = long long 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<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>'} to 'std::map<long long int, int>::key_type&&' {aka 'long long int&&'}
  524 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~
a.cc:42:14: error: no match for 'operator[]' (operand types are 'std::map<long long int, int>' and '__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>'})
   42 |     if (count[list[i]].first==1){
      |              ^
/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 = long long int; _Tp = int; _Compare = std::less<long long int>; _Alloc = std::allocator<std::pair<const long long int, int> >; mapped_type = int; key_type = long long 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<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>'} to 'const std::map<long long int, int>::key_type&' {aka 'const long long 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 = long long int; _Tp = int; _Compare = std::less<long long int>; _Alloc = std::allocator<std::pair<const long long int, int> >; mapped_type = int; key_type = long long 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<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>'} to 'std::map<long long int, int>::key_type&&' {aka 'long long int&&'}
  524 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~
a.cc:50:14: error: no match for 'operator[]' (operand types are 'std::map<long long int, int>' and '__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>'})
   50 |     if (count[list[i+1]].first==0){
      |              ^
/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 = long long int; _Tp = int; _Compare = std::less<long long int>; _Alloc = std::allocator<std::pair<const long long int, int> >; mapped_type = int; key_type = long long 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<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>'} to 'const std::map<long long int, int>::key_type&' {aka 'const long long 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 = long long int; _Tp = int; _Compare = std::less<long long int>; _Alloc = std::allocator<std::pair<const long long int, int> >; mapped_type = int; key_type = long long 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<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>'} to 'std::map<long long int, int>::key_type&&' {aka 'long long int&&'}
  524 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~
a.cc:53:7: error: expected ',' or ';' before 'int'
   53 |       int ans_2=pow(bonus+1, 2)+delicious-list[k].second+list[i].second;
      |       ^~~
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:14: error: no match for 'operator[]' (operand types are 'std::map<long long int, int>' and '__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>'})
   55 |         count[list[i]].first++;
      |              ^
/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 = long long int; _Tp = int; _Compare = std::less<long long int>; _Alloc = std::allocator<std::pair<const long long int, int> >; mapped_type = int; key_type = long long 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<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>'} to 'const std::map<long long int, int>::key_type&' {aka 'const long long 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 = long long int; _Tp = int; _Compare = std::less<long long int>; _A