Language: C++

#include<bits/stdc++.h>
using namespace std;
int n,k;
set<long long>s,s2;
pair<long long,long long>a[100003],c[100003];
vector<long long>v[100003];
bool can[100003];
bool cmp(pair<int,int>a,pair<int,int>b){
	return a.first>b.first;
}
bool cmp2(int a,int b){
	return a>b;
}
int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		cin>>a[i].second>>a[i].first;
		if(c[a[i].second-1].first<a[i].first)
			c[a[i].second-1].first=a[i].first,
			c[a[i].second-1].second=i;
		s2.insert(a[i].second);
	}
	int k2=k;
	sort(a,a+n);sort(c,c+n,cmp);
	long long ans=0,ans2=int(min(int(k),int(s2.size())))*int(min(int(k),int(s2.size())));
	for(int i=0;k>=0&&c[i].first!=0;i++,k--)ans2=ans2+c[i].first,can[c[i].second]=1;
	vector<int>v;
	for(int i=0;i<n;i++)if(!can[i])v.push_back(a[i].first);
	sort(v.begin(),v.end(),cmp2);
	for(int i=0;i<k;i++)ans2+=v[i];
	for(int i=0;i<k2;i++)
		ans+=a[n-1-i].first,
		s.insert(a[n-1-i].second);
	cout<<max(1ll*(ans+s.size()*s.size()),1ll*ans2);
}

Compiler output:
a.cc: In function 'int main()':
a.cc:35:18: error: no matching function for call to 'max(long long unsigned int, long long int)'
   35 |         cout<<max(1ll*(ans+s.size()*s.size()),1ll*ans2);
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:35:18: note:   deduced conflicting types for parameter 'const _Tp' ('long long unsigned int' and 'long long int')
   35 |         cout<<max(1ll*(ans+s.size()*s.size()),1ll*ans2);
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:35:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long unsigned int'
   35 |         cout<<max(1ll*(ans+s.size()*s.size()),1ll*ans2);
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~