Language: C++

#include <bits/stdc++.h>
#include <iostream>
#include <utility> // pair
#include <string>
#include <vector>
#define MAX_N 100001
#define rep(i, n) for(ll i=0; i<n; i++)
#define repq(i, k, n) for(ll i=k; i<n; i++)
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n, k;
P s[MAX_N];
vector<P> p, q; // 取ったダブリ寿司, 取っていない新規寿司
set<ll> t; // 取った寿司の種類を記録

signed main(){
    cin >> n >> k;
    rep(i, n){
        ll t, d;
        cin >> t >> d;
        s[i] = P(d, t);
    }
    // sort(s, s+n, greater<P>());
    ll ts = 0;
    rep(i, k){
        ts += s[i].first;
        if(t.find(s[i].second) != t.end()) p.pb(s[i]);
        t.insert(s[i].second);
    }
    reverse(p.begin(), p.end());
    ll x = t.size();
    repq(i, k, n){
        if(t.find(s[i].second) != t.end()) continue;
        q.pb(s[i]);
    }
    ll ret = ts;
    rep(i, min(p.size(), q.size())){
        if(t.find(q) != t.end()) continue;
        t.insert(q);
        ret = max(ret, ts + x * x);
        ts += q[i].first - p[i].first;
        x++;
    }
    ret = max(ret, ts + x * x);
    cout << ret << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:40:18: error: no matching function for call to 'std::set<long long int>::find(std::vector<std::pair<long long int, long long int> >&)'
   40 |         if(t.find(q) != t.end()) continue;
      |            ~~~~~~^~~
In file included from /usr/include/c++/14/set:63,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:158,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_set.h:806:9: note: candidate: 'template<class _Kt> decltype (std::set<_Key, _Compare, _Alloc>::iterator{((std::set<_Key, _Compare, _Alloc>*)this)->std::set<_Key, _Compare, _Alloc>::_M_t._M_find_tr(__x)}) std::set<_Key, _Compare, _Alloc>::find(const _Kt&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>]'
  806 |         find(const _Kt& __x)
      |         ^~~~
/usr/include/c++/14/bits/stl_set.h:806:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_set.h: In substitution of 'template<class _Kt> decltype (std::set<long long int>::iterator{((std::set<long long int>*)this)->std::set<long long int>::_M_t.std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::_M_find_tr(__x)}) std::set<long long int>::find(const _Kt&) [with _Kt = std::vector<std::pair<long long int, long long int> >]':
a.cc:40:18:   required from here
   40 |         if(t.find(q) != t.end()) continue;
      |            ~~~~~~^~~
/usr/include/c++/14/bits/stl_set.h:807:45: error: no matching function for call to 'std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::_M_find_tr(const std::vector<std::pair<long long int, long long int> >&)'
  807 |         -> decltype(iterator{_M_t._M_find_tr(__x)})
      |                              ~~~~~~~~~~~~~~~^~~~~
In file included from /usr/include/c++/14/map:62,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:152:
/usr/include/c++/14/bits/stl_tree.h:1291:9: note: candidate: 'template<class _Kt, class _Req> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_find_tr(const _Kt&) [with _Req = _Kt; _Key = long long int; _Val = long long int; _KeyOfValue = std::_Identity<long long int>; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>]'
 1291 |         _M_find_tr(const _Kt& __k)
      |         ^~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:1291:9: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/14/string:49,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/stl_function.h: In substitution of 'template<class _Func, class _SfinaeType> using std::__has_is_transparent_t = typename std::__has_is_transparent<_Func, _SfinaeType>::type [with _Func = std::less<long long int>; _SfinaeType = std::vector<std::pair<long long int, long long int> >]':
/usr/include/c++/14/bits/stl_tree.h:1289:9:   required by substitution of 'template<class _Kt> decltype (std::set<long long int>::iterator{((std::set<long long int>*)this)->std::set<long long int>::_M_t.std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::_M_find_tr(__x)}) std::set<long long int>::find(const _Kt&) [with _Kt = std::vector<std::pair<long long int, long long int> >]'
 1289 |                typename _Req = __has_is_transparent_t<_Compare, _Kt>>
      |                ^~~~~~~~
a.cc:40:18:   required from here
   40 |         if(t.find(q) != t.end()) continue;
      |            ~~~~~~^~~
/usr/include/c++/14/bits/stl_function.h:1427:11: error: no type named 'type' in 'struct std::__has_is_transparent<std::less<long long int>, std::vector<std::pair<long long int, long long int> >, void>'
 1427 |     using __has_is_transparent_t
      |           ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_set.h: In substitution of 'template<class _Kt> decltype (std::set<long long int>::iterator{((std::set<long long int>*)this)->std::set<long long int>::_M_t.std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::_M_find_tr(__x)}) std::set<long long int>::find(const _Kt&) [with _Kt = std::vector<std::pair<long long int, long long int> >]':
a.cc:40:18:   required from here
   40 |         if(t.find(q) != t.end()) continue;
      |            ~~~~~~^~~
/usr/include/c++/14/bits/stl_tree.h:1300:9: note: candidate: 'template<class _Kt, class _Req> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::const_iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_find_tr(const _Kt&) const [with _Req = _Kt; _Key = long long int; _Val = long long int; _KeyOfValue = std::_Identity<long long int>; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>]'
 1300 |         _M_find_tr(const _Kt& __k) const
      |         ^~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:1300:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_set.h:806:9: error: no matching function for call to 'std::_Rb_tree_const_iterator<long long int>::_Rb_tree_const_iterator(<brace-enclosed initializer list>)'
  806 |         find(const _Kt& __x)
      |         ^~~~
/usr/include/c++/14/bits/stl_tree.h:346:7: note: candidate: 'std::_Rb_tree_const_iterator<_Tp>::_Rb_tree_const_iterator(const iterator&) [with _Tp = long long int; iterator = std::_Rb_tree_const_iterator<long long int>::iterator]'
  346 |       _Rb_tree_const_iterator(const iterator& __it) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:346:7: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/14/bits/stl_tree.h:343:7: note: candidate: 'std::_Rb_tree_const_iterator<_Tp>::_Rb_tree_const_iterator(_Base_ptr) [with _Tp = long long int; _Base_ptr = const std::_Rb_tree_node_base*]'
  343 |       _Rb_tree_const_iterator(_Base_ptr __x) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:343:7: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/14/bits/stl_tree.h:339:7: note: candidate: 'std::_Rb_tree_const_iterator<_Tp>::_Rb_tree_const_iterator() [with _Tp = long long int]'
  339 |       _Rb_tree_const_iterator() _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:339:7: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/14/bits/stl_tree.h:324:12: note: candidate: 'constexpr std::_Rb_tree_const_iterator<long long int>::_Rb_tree_const_iterator(const std::_Rb_tree_const_iterator<long long int>&)'
  324 |     struct _Rb_tree_const_iterator
      |            ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:324:12: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/14/bits/stl_tree.h:324:12: note: candidate: 'constexpr std::_Rb_tree_const_iterator<long long int>::_Rb_tree_const_iterator(std::_Rb_tree_const_iterator<long long int>&&)'
/usr/include/c++/14/bits/stl_tree.h:324:12: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/14/bits/stl_set.h:812:9: note: candidate: 'template<class _Kt> decltype (std::set<_Key, _Compare, _Alloc>::const_iterator{((const std::set<_Key, _Compare, _Alloc>*)this)->std::set<_Key, _Compare, _Alloc>::_M_t._M_find_tr(__x)}) std::set<_Key, _Compare, _Alloc>::find(const _Kt&) const [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>]'
  812 |         find(const _Kt& __x) const
      |         ^~~~
/usr/include/c++/14/bits/stl_set.h:812:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_set.h: In substitution of 'template<class _Kt> decltype (std::set<long long int>::const_iterator{((const std::set<long long int>*)this)->std::set<long long int>::_M_t.std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::_M_find_tr(__x)}) std::set<long long int>::find(const _Kt&) const [with _Kt = std::vector<std::pair<long long int, long long int> >]':
a.cc:40:18:   required from here
   40 |         if(t.find(q) != t.end()) continue;
      |            ~~~~~~^~~
/usr/include/c++/14/bits/stl_set.h:813:51: error: no matching function for call to 'std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::_M_find_tr(const std::vector<std::pair<long long int, long long int> >&) const'
  813 |         -> decltype(const_iterator{_M_t._M_find_tr(__x)})
      |                                    ~~~~~~~~~~~~~~~^~~~~
/usr/include/c++/14/bits/stl_tree.h:1291:9: note: candidate: 'template<class _Kt, class _Req> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_find_tr(const _Kt&) [with _Req = _Kt; _Key = long long int; _Val = long long int; _KeyOfValue = std::_Identity<long long int>; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>]'
 1291 |         _M_find_tr(const _Kt& __k)
      |         ^~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:1291:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_tree.h:1300:9: note: candidate: 'template<class _Kt, class _Req> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::const_iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_find_tr(const _Kt&) const [with _Req = _Kt; _Key = long long int; _Val = long long int; _KeyOfValue = std::_Identity<long long int>; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>]'
 1300 |         _M_find_tr(const _Kt& __k) const
      |         ^~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:1300:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_set.h:812:9: error: no m