Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};

template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
mt19937 _mt(chrono::steady_clock::now().time_since_epoch().count());
ll getrnd(ll l,ll r){return uniform_int_distribution<ll>(l,r-1)(_mt);}
#define _cTime (chrono::system_clock::now())
#define progress (chrono::duration_cast<chrono::milliseconds>(_cTime-_sTime).count())
#define reset _sTime=_cTime
auto reset;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k,t,d;
	cin>>n>>k;
	vector<pll> v(n);
	rep(i,n) cin>>v[i].fs>>v[i].sc;
	sort(all(v),[](const pll &a,const pll &b){
		return a.sc>b.sc;
	});
	ll ans=0,sum=0;
	ll bonus=0;
	set<ll> s;
	priority_queue<ll> q;
	rep(i,n){
		if(i<k){
			sum+=v[i].sc;
			if(s.find(v[i].fs)!=s.end()){
				q.push(v[i].sc);
			}
			s.insert(v[i].fs);
		}
		else{
			if(q.empty()||s.find(v[i].fs)!=s.end())continue;
			ll waste=q.top();q.pop();
			sum-=waste;sum+=v[i].sc;
			s.insert(v[i].fs);
		}
		chmax(ans,s.size()*s.size()+sum);
	}
	cout<<ans<<endl;
	
}



Compiler output:
a.cc: In function 'int main()':
a.cc:85:22: error: no matching function for call to 'chmax(ll&, long long unsigned int)'
   85 |                 chmax(ans,s.size()*s.size()+sum);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:39:23: note: candidate: 'template<class T> bool chmax(T&, T)'
   39 | template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
      |                       ^~~~~
a.cc:39:23: note:   template argument deduction/substitution failed:
a.cc:85:22: note:   deduced conflicting types for parameter 'T' ('long long int' and 'long long unsigned int')
   85 |                 chmax(ans,s.size()*s.size()+sum);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~