Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> plus;
    vector<int> minus;
    int x;
    for (int i = 0; i < N; i++){
        cin >> x;
        if (x < 0){
            minus.push_back(x);
        }
        else{
            plus.push_back(x);
        }
    }
    reverse(minus.begin(), minus.end());
    int tmp_p = -1;
    int tmp_m = -1;
    int cnt = 0;
    int num = 0;
    int cnt1 = 100000000;
    int cnt2 = 100000000;
    if (plus.size() >= K){
        cnt1 = plus[K-1];
    }
    if (minus.size() >= K) {
        cnt2 = minus[K-1];
    }

    while (cnt < K) {
        if (tmp_p+1 < plus.size()){
            if (plus[tmp_p+1] == num){
                cnt++;
                tmp_p++;
            }
        }
        if (tmp_m+1 < minus.size()){
            if (minus[tmp_m+1] == -num){
                cnt++;
                tmp_m++;
            }
        }
        
        num++;
    }
    if (cnt == K){
        if (tmp_p >= 0 && tmp_m >= 0){
            cout << min(cnt1, cnt2, {2 * min(plus[tmp_p], -minus[tmp_m]) + max(plus[tmp_p], -minus[tmp_m])}) << endl;
        }
        else if (tmp_p < 0){
            cout << min({cnt1, cnt2, -minus[tmp_m]}) << endl;
        }
        else {
            cout << min({cnt1, cnt2, plus[tmp_p]}) << endl;
        }
    else if (tmp_p != 0 && tmp_m != 0){
        cout << min({cnt1, cnt2, min(plus[tmp_p-1], -minus[tmp_m]) + max(plus[tmp_p-1], -minus[tmp_m]), min(plus[tmp_p], -minus[tmp_m-1]) + max(plus[tmp_p], -minus[tmp_m-1])}) << endl;
    }
    else{
        cout << min(cnt1, cnt2) << endl;
    }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:54:24: error: no matching function for call to 'min(int&, int&, <brace-enclosed initializer list>)'
   54 |             cout << min(cnt1, cnt2, {2 * min(plus[tmp_p], -minus[tmp_m]) + max(plus[tmp_p], -minus[tmp_m])}) << endl;
      |                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:   candidate expects 2 arguments, 3 provided
/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:   template argument deduction/substitution failed:
a.cc:54:24: note:   couldn't deduce template parameter '_Compare'
   54 |             cout << min(cnt1, cnt2, {2 * min(plus[tmp_p], -minus[tmp_m]) + max(plus[tmp_p], -minus[tmp_m])}) << endl;
      |                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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, 3 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:   candidate expects 2 arguments, 3 provided
a.cc:62:5: error: expected '}' before 'else'
   62 |     else if (tmp_p != 0 && tmp_m != 0){
      |     ^~~~
a.cc:52:18: note: to match this '{'
   52 |     if (cnt == K){
      |                  ^