Language: C++

#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;

int A, B, C, D, E, F;
string S, Sa, Sb, Sc;
long long int V[100000] = {};
long long int X[100000] = {};
typedef pair<double,int> Pi;
Pi N[100000] = {};
long long int ans = 0;
int main() {
	cin >> A >> B;
for(int i = 0;i < B;i++)cin >> V[i];
sort(V, V + B, greater<int>());
X[0] = V[A - 1];
X[1] = V[B - 1];
for(int i = 0;i < B;i++){
if(V[i] >= X[0]);
else{
	if(abs(X[0] - V[i]) > abs(X[1] - V[i]))ans += abs(X[1] - V[i]);
	else ans += abs(X[0] - V[i]);
}
int C = 0;
X[0] = V[A - 1];
X[1] = V[A];
for(int i = 0;i < B;i++){
if(V[i] >= X[0]);
else{
	if(abs(X[0] - V[i]) > abs(X[1] - V[i]))C += abs(X[1] - V[i]);
	else C += abs(X[0] - V[i]);
}
}	
long long int vans = 0;
sort(V, V + B);
X[0] = V[A - 1];
X[1] = V[B - 1];
for(int i = 0;i < B;i++){
if(V[i] <= X[0]);
else{
	if(abs(X[0] - V[i]) > abs(X[1] - V[i]))vans += abs(X[1] - V[i]);
	else vans += abs(X[0] - V[i]);
}
int D = 0;
X[0] = V[A - 1];
X[1] = V[A];
for(int i = 0;i < B;i++){
if(V[i] >= X[0]);
else{
	if(abs(X[0] - V[i]) > abs(X[1] - V[i]))D += abs(X[1] - V[i]);
	else D += abs(X[0] - V[i]);
}
}	
if(B < A)A = 0;
cout << min({ans, vans,C,D}()) + A << endl;

	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:57:28: error: expected ')' before '(' token
   57 | cout << min({ans, vans,C,D}()) + A << endl;
      |            ~               ^
      |                            )
a.cc:57:12: error: no matching function for call to 'min(<brace-enclosed initializer list>)'
   57 | cout << min({ans, vans,C,D}()) + A << endl;
      |         ~~~^~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 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, 1 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:   candidate expects 3 arguments, 1 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:2:
/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:   template argument deduction/substitution failed:
a.cc:57:12: note:   deduced conflicting types for parameter '_Tp' ('long long int' and 'int')
   57 | cout << min({ans, vans,C,D}()) + A << endl;
      |         ~~~^~~~~~~~~~~~~~~~~
/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, 1 provided
a.cc:60:2: error: expected '}' at end of input
   60 | }
      |  ^
a.cc:20:25: note: to match this '{'
   20 | for(int i = 0;i < B;i++){
      |                         ^
a.cc:60:2: error: expected '}' at end of input
   60 | }
      |  ^
a.cc:14:12: note: to match this '{'
   14 | int main() {
      |            ^