Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long mod = 1000000007;
const int INF = 1001001001;
vector<int> a;
ll n,m;
vector<ll> ruiseki;


ll f(ll x){
  ll y = 0;
  for(int i=0;i<n;i++){
  auto it = a.begin();
  advance(it,i);
  ll xx = x - *it;
  auto it2 = lower_bound(a.begin(),a.end(),xx);
  ll comb_at_i = n - (it2 - a.begin());
  y += comb_at_i;
  }
  return y;
}

ll g(ll x){
  ll y = 0;
  ll double_check = 0;
  ll minimum_check = INF;
  for(int i=0;i<n;i++){
  auto it = a.begin();
  advance(it,i);
  ll xx = x - *it;
  if(xx>a.at(n-1)) continue;
  auto it2 = lower_bound(a.begin(),a.end(),xx);
  ll left = it2 - a.begin() - 1;
  double_check += n-(it2-a.begin());
  minimum_check = min(minimum_check, (*it) + a.at(left+1));
  if(left>=0){
  y += ((ruiseki.at(n-1) - ruiseki.at(left)) + ((*it) * (n-(it2-a.begin()))));
  }else{
    y+= ruiseki.at(n-1) + ((*it) * (n-(it2-a.begin())));
  }
  }
  y -= (minimum_check * (double_check-m));
  return y;
}

int main(){
  cin >> n >> m;
  for(int i=0;i<n;i++){
    ll input;
    cin >> input;
    a.push_back(input);
  }
  sort(a.begin(),a.end());
  ll l = 0;
  ll r = a.at(n-1) * 2;
  ll c = (l+r)/2;
  while(r-l>1){
    if(f(c)<m) r = c; else l = c;
    c = (l+r)/2;
  }
  ruiseki.resize(n,0);
  ruiseki.at(0) = a.at(0);
  for(int i=1;i<n;i++){
    ruiseki.at(i) = ruiseki.at(i-1) + a.at(i);   
  }
     cout << g(l) << endl; 
}

Compiler output:
a.cc: In function 'll g(ll)':
a.cc:36:22: error: no matching function for call to 'min(ll&, int)'
   36 |   minimum_check = min(minimum_check, (*it) + a.at(left+1));
      |                   ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:36:22: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   36 |   minimum_check = min(minimum_check, (*it) + a.at(left+1));
      |                   ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:36:22: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   36 |   minimum_check = min(minimum_check, (*it) + a.at(left+1));
      |                   ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~