Language: C++

#include<bits/stdc++.h>
using namespace std;
const long long INFdesu=2E10;


int main(){
    int N,K;
    int X[100010];
    cin >> N >> K;
    long long minV=INFdesu;
    int left=0;
    int i;
    for(i=0;i<N;i++) {
        cin >> X[i];
        if (X[i]<0) left=i+1;
    }

    
    //最初左にi個行く
    for(i=1;i<=left && i<K && K-i<=N-left;i++){
        minV=min(minV,-2*X[left-i]+X[K-i+left-1]);
    }

    //最初右にi個行く
    for(i=1;i<=N-left && i<K && K-i<=left;i++){
        minV=min(minV,2*X[left+i-1]-X[left-K+i]);
    }

    if(left>=K) minV=min(minV,-X[left-K]);
    if(N-left>=K) minV=min(minV,X[left+K-1]);
    cout << minV << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:21:17: error: no matching function for call to 'min(long long int&, int)'
   21 |         minV=min(minV,-2*X[left-i]+X[K-i+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:21:17: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   21 |         minV=min(minV,-2*X[left-i]+X[K-i+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:21:17: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   21 |         minV=min(minV,-2*X[left-i]+X[K-i+left-1]);
      |              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:26:17: error: no matching function for call to 'min(long long int&, int)'
   26 |         minV=min(minV,2*X[left+i-1]-X[left-K+i]);
      |              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:26:17: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   26 |         minV=min(minV,2*X[left+i-1]-X[left-K+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
/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:26:17: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   26 |         minV=min(minV,2*X[left+i-1]-X[left-K+i]);
      |              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:29:25: error: no matching function for call to 'min(long long int&, int)'
   29 |     if(left>=K) minV=min(minV,-X[left-K]);
      |                      ~~~^~~~~~~~~~~~~~~~~
/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:29:25: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   29 |     if(left>=K) minV=min(minV,-X[left-K]);
      |                      ~~~^~~~~~~~~~~~~~~~~
/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
/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:29:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   29 |     if(left>=K) minV=min(minV,-X[left-K]);
      |                      ~~~^~~~~~~~~~~~~~~~~
a.cc:30:27: error: no matching function for call to 'min(long long int&, int&)'
   30 |     if(N-left>=K) minV=min(minV,X[left+K-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:30:27: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   30 |     if(N-left>=K) minV=min(minV,X[left+K-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
/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:30:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   30 |     if(N-left>=K) minV=min(minV,X[left+K-1]);
      |                        ~~~^~~~~~~~~~~~~~~~~~