Language: C++

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll n,k;
  cin>>n>>k
  vector<ll> t(n),d(n),a[100005];
  vector<pair<ll,ll>> p;
  set<ll> s;
  for(int i=0;i<n;i++){
    cin>>t[i]>>d[i];
    s.insert(t[i]);
    p.push_back(make_pair(d[i],t[i]));
    a[t[i]].push_back(d[i]);
  }
  sort(p.begin(),p.end(),greater<pair<ll,ll>>());
  set<ll> se;
  ll c1=0;
  for(int i=0;i<k;i++){
    c1+=p[i].first;
    se.insert(p[i].second);
  }
  c1+=se.size()*se.size();
  for(int i=0;i<100001;i++){
    if(!a[i].empty()){
      sort(a[i].begin(),a[i].end(),greater<ll>());
    }
  }
  ll c2=0,cnt=0;
  set<ll> ss;
  vector<bool> bo(100005,true);
  for(int i=0;i<n;i++){
    if(k-cnt<s.size()-ss.size()){
      c2+=p[i].first;
      ss.insert(p[i].second);
      bo[p[i].second]=false;
cnt++;
    }else{
      if(bo[p[i].second]){
 cnt++;
      c2+=p[i].first;
      ss.insert(p[i].second);
      bo[p[i].second]=false;
      }
    }
    if(cnt==k)break;
  }
  cout<<max(c1,c2+ss.size()*ss.size());
}
  
  

Compiler output:
a.cc: In function 'int main()':
a.cc:6:12: error: expected ';' before 'vector'
    6 |   cin>>n>>k
      |            ^
      |            ;
    7 |   vector<ll> t(n),d(n),a[100005];
      |   ~~~~~~    
a.cc:11:10: error: 't' was not declared in this scope
   11 |     cin>>t[i]>>d[i];
      |          ^
a.cc:11:16: error: 'd' was not declared in this scope
   11 |     cin>>t[i]>>d[i];
      |                ^
a.cc:14:5: error: 'a' was not declared in this scope
   14 |     a[t[i]].push_back(d[i]);
      |     ^
a.cc:25:9: error: 'a' was not declared in this scope
   25 |     if(!a[i].empty()){
      |         ^
a.cc:48:12: error: no matching function for call to 'max(long long int&, long long unsigned int)'
   48 |   cout<<max(c1,c2+ss.size()*ss.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:48:12: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
   48 |   cout<<max(c1,c2+ss.size()*ss.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:48:12: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   48 |   cout<<max(c1,c2+ss.size()*ss.size());
      |         ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~