Language: C++

#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define int ll

int k,n;
vector<P> a;


signed main(){

  cin>>n>>k;

  rep(i,n){
    int t,d;
    cin>>t>>d;
    a.PB(P(d,t));
  }

  sort(all(a));
  reverse(all(a));

  int sum=0;
  int ans=0;

  map<int,int> mp;
  priority_queue<P> q;

  rep(i,k){
    sum+=a[i].F;
    if(mp[a[i].S])
      q.push(a[i]);
    mp[a[i].S]++;
  }

  ans = sum+mp.size()*mp.size();

  FOR(i,k,n){
    if(q.empty()) break;
    if(mp[a[i].S]) continue;
    P p = q.top();
    q.pop();
    sum-=p.F;
    sum+=a[i].F;
    mp[a[i].S]++;
    ans = max(ans,sum+mp.size()*mp.size());
  }


  cout<<ans<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:64:14: error: no matching function for call to 'max(long long int&, long long unsigned int)'
   64 |     ans = max(ans,sum+mp.size()*mp.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:64:14: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
   64 |     ans = max(ans,sum+mp.size()*mp.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:64:14: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   64 |     ans = max(ans,sum+mp.size()*mp.size());
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~