Language: C++

#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){
  int n,k;
  cin >> n >> k;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    int temp;
    cin >> temp;
    a[i] = temp;
  }

  partial_sort(a.begin(),a.end(),k,greater<int>());

  int ans = 0;
  for(int i = 0; i < k; i++){
    ans += a[i];
  }

  cout << ans << endl;
  
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:33:15: error: no matching function for call to 'partial_sort(std::vector<int>::iterator, std::vector<int>::iterator, int&, std::greater<int>)'
   33 |   partial_sort(a.begin(),a.end(),k,greater<int>());
      |   ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_algo.h:4608:5: note: candidate: 'template<class _RAIter> void std::partial_sort(_RAIter, _RAIter, _RAIter)'
 4608 |     partial_sort(_RandomAccessIterator __first,
      |     ^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4608:5: note:   candidate expects 3 arguments, 4 provided
/usr/include/c++/14/bits/stl_algo.h:4647:5: note: candidate: 'template<class _RAIter, class _Compare> void std::partial_sort(_RAIter, _RAIter, _RAIter, _Compare)'
 4647 |     partial_sort(_RandomAccessIterator __first,
      |     ^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4647:5: note:   template argument deduction/substitution failed:
a.cc:33:15: note:   deduced conflicting types for parameter '_RAIter' ('__gnu_cxx::__normal_iterator<int*, std::vector<int> >' and 'int')
   33 |   partial_sort(a.begin(),a.end(),k,greater<int>());
      |   ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:359:1: note: candidate: 'template<class _ExecutionPolicy, class _RandomAccessIterator, class _Compare> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::partial_sort(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare)'
  359 | partial_sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __middle,
      | ^~~~~~~~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:359:1: note:   candidate expects 5 arguments, 4 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:364:1: note: candidate: 'template<class _ExecutionPolicy, class _RandomAccessIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::partial_sort(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator)'
  364 | partial_sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __middle,
      | ^~~~~~~~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:364:1: note:   template argument deduction/substitution failed:
a.cc:33:15: note:   deduced conflicting types for parameter '_RandomAccessIterator' ('__gnu_cxx::__normal_iterator<int*, std::vector<int> >' and 'int')
   33 |   partial_sort(a.begin(),a.end(),k,greater<int>());
      |   ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~