Language: C++

#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
//#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

signed main(){
  int n,k;cin>>n>>k;pair<int,int> all[100000];rep(i,n)cin>>all[i].second>>all[i].first;
  sort(all,all+n,greater<pair<int,int>>());
  pair<int,int> em[100001];
  rep(i,100001){
    em[i].first = 0;em[i].second = i;
  }
  rep(i,n){
    em[all[i].second].first = max(em[all[i].second].first,all[i].first);
  }
  int netaCount = 0;
  rep(i,100001){
    if(em[i].first > 0){
      netaCount++;
    }
  }
  ll ans = 0, used = 0;stack<int> changable,unchangable;bool g[100001], gg[100001];rep(i,100001)g[i] = false;
  rep(i,k){
    ans += all[i].first;
    if(!g[all[i].second]){
      used++;g[all[i].second] = gg[all[i].second] = true;em[all[i].second].first = 0;
      unchangable.push(i);
    }else{
      changable.push(i);
    }
  }

  ans += used * used;
  sort(em,em+100001,greater<pair<int,int>>());
  int changeCount = 0;ll karians = ans;
  //cout << netaCount << " " << used << endl;
  int j = max(netaCount - used,k);
  rep(i,j+1){
    int Ind;
    if(!unchangable.empty() && changable.empty()){
      Ind = unchangable.top();unchangable.pop();
      karians = karians - all[Ind].first + em[i].first;
    }else{
      Ind = changable.top();changable.pop();
      karians = karians + 2 * used + 1 - all[Ind].first + em[i].first;
      used++;
    }
    //cout << all[Ind].first << " " << em[i].second << endl;
    ans = max(ans, karians);
  }
  cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:43:14: error: no matching function for call to 'max(ll, int&)'
   43 |   int j = max(netaCount - used,k);
      |           ~~~^~~~~~~~~~~~~~~~~~~~
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:43:14: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   43 |   int j = max(netaCount - used,k);
      |           ~~~^~~~~~~~~~~~~~~~~~~~
/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:43:14: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   43 |   int j = max(netaCount - used,k);
      |           ~~~^~~~~~~~~~~~~~~~~~~~