Language: C++

#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
    cin>>N>>K;
    vec t(N), d(N);
    rep(i,N) cin>>t[i]>>d[i];
    vec ord(N);
    rep(i,N) ord[i] = i;
    sort(ord.begin(),ord.end(),[&](ll x, ll y){
        if(d[x] == d[y]) return t[y] < t[x];
        return d[y] < d[x];
    });
    vec rest(0);//種類数に影響ない寿司のおいしさを入れていく
    set<ll> kind;
    ll ans = 0;
    rep(i,K){
        ll index = ord[i];
        auto ite = kind.find(t[index]);
        ans += d[index];
        if(ite == kind.end()){
            kind.insert(t[index]);
        }else{
            rest.push_back(d[index]);
        }
    }
    ll temp = ans;
    ll rindex = rest.size() - 1;
    //rep(i,rindex+1) cout<<rest.at(i)<<endl;
    ans += kind.size()*kind.size();
    reps(i,K,N){
        if(K == kind.size()) break;
        ll index = ord[i];
        auto ite = kind.find(t[index]);
        if(ite == kind.end()){
            //cout<<ans<<endl;
            kind.insert(t[index]);
            //cout<<temp<<' '<<rest.at(rindex)<<' '<<d[i]<<endl;
            temp -= rest.at(rindex--) - d[index];
            //cout<<temp<<endl;
            //cout<<endl;
            ans = max(ans,temp + kind.size()*kind.size());
        }
    }
    cout<<ans<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:56:22: error: no matching function for call to 'max(ll&, long long unsigned int)'
   56 |             ans = max(ans,temp + kind.size()*kind.size());
      |                   ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 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:56:22: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
   56 |             ans = max(ans,temp + kind.size()*kind.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:
/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:56:22: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   56 |             ans = max(ans,temp + kind.size()*kind.size());
      |                   ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~