Language: C++

#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;

const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main()
{
    ll n,k;
    cin >> n >> k;
    vector<ll> v[100010];
    for(int i = 0; i < n; i++){
        ll t,d;
        cin >> t >> d;
        v[t].emplace_back(d);
    }
    for(int i = 0; i < 100010; i++) sort(v[i].rbegin(),v[i].rend());
    vector<ll> use,non;
    for(int i = 0; i < 100010; i++){
        int flag = 0;
        for(auto x: v[i]){
            if(flag) non.emplace_back(x);
            else{
                use.emplace_back(x);
                flag = 1;
            }
        }
    }
    sort(use.rbegin(),use.rend()),sort(non.rbegin(),non.rend());
    vector<ll> use_sum = {0},non_sum = {0};
    for(auto x: use){
        use_sum.emplace_back(use_sum.back()+x);
    }
    for(auto x: non){
        non_sum.emplace_back(non_sum.back()+x);
    }
    while(non_sum.size() < k) non_sum.emplace_back(0);

    ll ans = 0;
    for(int i = 1; i <= min(k,(int)use.size()); i++){
        //if(i >= use_sum.size()) break;
        //if(k-i >= non_sum.size()) continue;
        ans = max(ans,use_sum[i]+non_sum[k-i]+i*i);
    }
    cout << ans << endl;

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:45:28: error: no matching function for call to 'min(ll&, int)'
   45 |     for(int i = 1; i <= min(k,(int)use.size()); i++){
      |                         ~~~^~~~~~~~~~~~~~~~~~~
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:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:45:28: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   45 |     for(int i = 1; i <= min(k,(int)use.size()); i++){
      |                         ~~~^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281: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:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:45:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   45 |     for(int i = 1; i <= min(k,(int)use.size()); i++){
      |                         ~~~^~~~~~~~~~~~~~~~~~~