Language: C++

#include "bits/stdc++.h"
#include <chrono> 
 
using namespace std;
using namespace std::chrono; 
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
#define gcd(ade,bde) __gcd(ade,bde)
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
#define vc vector<char>
#define pb(ade) push_back(ade)
#define pp pop_back()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define type(ade) typeid(ade).name();
#define starting() auto start = high_resolution_clock::now()
#define ending() auto stop = high_resolution_clock::now();\
auto duration = duration_cast<microseconds>(stop - start);\
cerr << "\n" << "\n" << "Execution Time : "<< duration.count()/1000 << " ms" << "\n"

template <typename T1>
void print(vector<T1> arr) {
	int l = (int)arr.size();
	cerr << "[" ;
	for(int i = 0; i < l; i++) { 
		(i == l - 1) ? cerr << arr[i] : cerr << arr[i] << "," ;
	}
	cerr << "]" << "\n";
}

template <typename T1>
void printArr(int arr[], int l) {
	cerr << "[" ;
	for (int i = 0; i < (int)l; i++) { 
		(i == l-1) ? cerr << arr[i] : cerr << arr[i] << "," ;
	}
	cerr << "]" << "\n";
}

template <typename T1>
void console(vector<vector<T1>> arr) {
	for (int i = 0; i < (int)arr.size(); ++i) { 
		cerr << "\n" << " [" ; 
	    for(int j = 0; j < (int)arr[i].size(); ++j) { 
			(j == (int)arr[i].size() - 1) ? cerr << arr[i][j] : cerr << arr[i][j] << "," ;
		}
	    cerr << "]";
	} 
	cerr << "\n";
} 
template <typename T1,typename T2>
void mapped(map<T1,T2> m) { 
	for(auto ite = m.begin(); ite != m.end(); ++ite){ 
		cerr << "'" << ite->first << "'"<< " : " << ite->second << "\n";
	}
}
 
template <typename T1 , typename T2>
void mappedArr(map<T1,vector<T2>> m) {
	for (auto ity = m.begin(); ity != m.end(); ++ity) {
		cerr << "'" << ity->first << "'" << " : " << "[";
        for (int i = 0; i < (int)ity->second.size(); ++i) {
			(i == (int)ity->second.size() - 1) ? cerr << ity->second[i] : cerr << ity->second[i] << ",";
		}
		cerr << "]" << "\n";
	}
}
 
string int_to_string(int x) {
    stringstream ss;
	ss << x;
	string ni = ss.str();
	return ni;
}
int char_to_int(char c) {
	int n = (int)c - 48;
	return n;
}
int string_to_int(string x) {
	int n;
	stringstream s(x);
	s >> n;
	return n;
}
 
template <typename T1, typename T2>
void vectPair(vector<pair<T1,T2>> vp) {
	for (int arrp = 0; arrp< (int)vp.size(); ++arrp){
		cerr << "(" << vp[arrp].first << "," << vp[arrp].second << ")" << "\n" ;
	}
}

//unordered_map<int,int> um;
//unordered_set<int> us;
//set<int> s;
// v.front() gives the first element of vector
// v.back()  gives the last element of vector
// insert erase substr
//g++ -o Legendary-Grandmaster Legendary-Grandmaster.cpp&Legendary-Grandmaster.exe
//cd C:\Users\158si\Desktop\Algorithim\codeForces\elite
// for-bash cd C:/Users/158si/Desktop/Algorithim/codeForces/elite
//memset(arr,element,sizeofarray);//Converts the value ch to unsigned char and copies it
// into each of the first n characters of the object pointed to by str[].
//g++ -o impulse.exe impulse.cpp
//puts

const int len1 = 3, len2 = 5;

void consoleArr(int arr[len1][len2]){
	for (int i = 0; i < len1; ++i) {
		for (int j = 0; j < len2; ++j) {
			cerr << arr[i][j] << " ";
		}
		cerr << "\n";
	}
	cerr << "\n";
}
 
const int MOD = 1e9 + 7;
const ll INF = 1e18L + 5;


int main(){
	IOS;  
	int n,k;
	cin >> n >> k;
	vector<double> v(n);
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
	}
	sort(v.rbegin(),v.rend());
	double ans = 0;
	for(int i = 0; i < k; ++i) {
		double x = v[i];
		ans += ((x*(x+1))/2)/x;
	}
	cout << ans;
	
	return 0; 
}














#include "bits/stdc++.h"
#include <chrono> 
 
using namespace std;
using namespace std::chrono; 
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
#define gcd(ade,bde) __gcd(ade,bde)
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
#define vc vector<char>
#define pb(ade) push_back(ade)
#define pp pop_back()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define type(ade) typeid(ade).name();
#define starting() auto start = high_resolution_clock::now()
#define ending() auto stop = high_resolution_clock::now();\
auto duration = duration_cast<microseconds>(stop - start);\
cerr << "\n" << "\n" << "Execution Time : "<< duration.count()/1000 << " ms" << "\n"

template <typename T1>
void print(vector<T1> arr) {
	int l = (int)arr.size();
	cerr << "[" ;
	for(int i = 0; i < l; i++) { 
		(i == l - 1) ? cerr << arr[i] : cerr << arr[i] << "," ;
	}
	cerr << "]" << "\n";
}

template <typename T1>
void printArr(int arr[], int l) {
	cerr << "[" ;
	for (int i = 0; i < (int)l; i++) { 
		(i == l-1) ? cerr << arr[i] : cerr << arr[i] << "," ;
	}
	cerr << "]" << "\n";
}

template <typename T1>
void console(vector<vector<T1>> arr) {
	for (int i = 0; i < (int)arr.size(); ++i) { 
		cerr << "\n" << " [" ; 
	    for(int j = 0; j < (int)arr[i].size(); ++j) { 
			(j == (int)arr[i].size() - 1) ? cerr << arr[i][j] : cerr << arr[i][j] << "," ;
		}
	    cerr << "]";
	} 
	cerr << "\n";
} 
template <typename T1,typename T2>
void mapped(map<T1,T2> m) { 
	for(auto ite = m.begin(); ite != m.end(); ++ite){ 
		cerr << "'" << ite->first << "'"<< " : " << ite->second << "\n";
	}
}
 
template <typename T1 , typename T2>
void mappedArr(map<T1,vector<T2>> m) {
	for (auto ity = m.begin(); ity != m.end(); ++ity) {
		cerr << "'" << ity->first << "'" << " : " << "[";
        for (int i = 0; i < (int)ity->second.size(); ++i) {
			(i == (int)ity->second.size() - 1) ? cerr << ity->second[i] : cerr << ity->second[i] << ",";
		}
		cerr << "]" << "\n";
	}
}
 
string int_to_string(int x) {
    stringstream ss;
	ss << x;
	string ni = ss.str();
	return ni;
}
int char_to_int(char c) {
	int n = (int)c - 48;
	return n;
}
int string_to_int(string x) {
	int n;
	stringstream s(x);
	s >> n;
	return n;
}
 
template <typename T1, typename T2>
void vectPair(vector<pair<T1,T2>> vp) {
	for (int arrp = 0; arrp< (int)vp.size(); ++arrp){
		cerr << "(" << vp[arrp].first << "," << vp[arrp].second << ")" << "\n" ;
	}
}

//unordered_map<int,int> um;
//unordered_set<int> us;
//set<int> s;
// v.front() gives the first element of vector
// v.back()  gives the last element of vector
// insert erase substr
//g++ -o Legendary-Grandmaster Legendary-Grandmaster.cpp&Legendary-Grandmaster.exe
//cd C:\Users\158si\Desktop\Algorithim\codeForces\elite
// for-bash cd C:/Users/158si/Desktop/Algorithim/codeForces/elite
//memset(arr,element,sizeofarray);//Converts the value ch to unsigned char and copies it
// into each of the first n characters of the object pointed to by str[].
//g++ -o impulse.exe impulse.cpp
//puts

const int len1 = 3, len2 = 5;

void consoleArr(int arr[len1][len2]){
	for (int i = 0; i < len1; ++i) {
		for (int j = 0; j < len2; ++j) {
			cerr << arr[i][j] << " ";
		}
		cerr << "\n";
	}
	cerr << "\n";
}
 
const int MOD = 1e9 + 7;
const ll INF = 1e18L + 5;


int main(){
	IOS;  
	int n,k;
	cin >> n >> k;
	vector<double> v(n);
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
	}
	sort(v.rbegin(),v.rend());
	double ans = 0;
	for(int i = 0; i < k; ++i) {
		double x = v[i];
		ans += ((x*(x+1))/(2*x));
	}
	cout << ans;
	
	return 0; 
}




































Compiler output:
a.cc:184:6: error: redefinition of 'template<class T1> void print(std::vector<_Tp>)'
  184 | void print(vector<T1> arr) {
      |      ^~~~~
a.cc:26:6: note: 'template<class T1> void print(std::vector<_Tp>)' previously declared here
   26 | void print(vector<T1> arr) {
      |      ^~~~~
a.cc:194:6: error: redefinition of 'template<class T1> void printArr(int*, int)'
  194 | void printArr(int arr[], int l) {
      |      ^~~~~~~~
a.cc:36:6: note: 'template<class T1> void printArr(int*, int)' previously declared here
   36 | void printArr(int arr[], int l) {
      |      ^~~~~~~~
a.cc:203:6: error: redefinition of 'template<class T1> void console(std::vector<std::vector<_Tp> >)'
  203 | void console(vector<vector<T1>> arr) {
      |      ^~~~~~~
a.cc:45:6: note: 'template<class T1> void console(std::vector<std::vector<_Tp> >)' previously declared here
   45 | void console(vector<vector<T1>> arr) {
      |      ^~~~~~~
a.cc:214:6: error: redefinition of 'template<class T1, class T2> void mapped(std::map<T1, T2>)'
  214 | void mapped(map<T1,T2> m) {
      |      ^~~~~~
a.cc:56:6: note: 'template<class T1, class T2> void mapped(std::map<T1, T2>)' previously declared here
   56 | void mapped(map<T1,T2> m) {
      |      ^~~~~~
a.cc:221:6: error: redefinition of 'template<class T1, class T2> void mappedArr(std::map<T1, std::vector<_ValT> >)'
  221 | void mappedArr(map<T1,vector<T2>> m) {
      |      ^~~~~~~~~
a.cc:63:6: note: 'template<class T1, class T2> void mappedArr(std::map<T1, std::vector<_ValT> >)' previously declared here
   63 | void mappedArr(map<T1,vector<T2>> m) {
      |      ^~~~~~~~~
a.cc:231:8: error: redefinition of 'std::string int_to_string(int)'
  231 | string int_to_string(int x) {
      |        ^~~~~~~~~~~~~
a.cc:73:8: note: 'std::string int_to_string(int)' previously defined here
   73 | string int_to_string(int x) {
      |        ^~~~~~~~~~~~~
a.cc:237:5: error: redefinition of 'int char_to_int(char)'
  237 | int char_to_int(char c) {
      |     ^~~~~~~~~~~
a.cc:79:5: note: 'int char_to_int(char)' previously defined here
   79 | int char_to_int(char c) {
      |     ^~~~~~~~~~~
a.cc:241:5: error: redefinition of 'int string_to_int(std::string)'
  241 | int string_to_int(string x) {
      |     ^~~~~~~~~~~~~
a.cc:83:5: note: 'int string_to_int(std::string)' previously defined here
   83 | int string_to_int(string x) {
      |     ^~~~~~~~~~~~~
a.cc:249:6: error: redefinition of 'template<class T1, class T2> void vectPair(std::vector<std::pair<_T1, _T2> >)'
  249 | void vectPair(vector<pair<T1,T2>> vp) {
      |      ^~~~~~~~
a.cc:91:6: note: 'template<class T1, class T2> void vectPair(std::vector<std::pair<_T1, _T2> >)' previously declared here
   91 | void vectPair(vector<pair<T1,T2>> vp) {
      |      ^~~~~~~~
a.cc:269:11: error: redefinition of 'const int len1'
  269 | const int len1 = 3, len2 = 5;
      |           ^~~~
a.cc:111:11: note: 'const int len1' previously defined here
  111 | const int len1 = 3, len2 = 5;
      |           ^~~~
a.cc:269:21: error: redefinition of 'const int len2'
  269 | const int len1 = 3, len2 = 5;
      |                     ^~~~
a.cc:111:21: note: 'const int len2' previously defined here
  111 | const int len1 = 3, len2 = 5;
      |                     ^~~~
a.cc:271:6: error: redefinition of 'void consoleArr(int (*)[5])'
  271 | void consoleArr(int arr[len1][len2]){
      |      ^~~~~~~~~~
a.cc:113:6: note: 'void consoleArr(int (*)[5])' previously defined here
  113 | void consoleArr(int arr[len1][len2]){
      |      ^~~~~~~~~~
a.cc:281:11: error: redefinition of 'const int MOD'
  281 | const int MOD = 1e9 + 7;
      |           ^~~
a.cc:123:11: note: 'const int MOD' previously defined here
  123 | const int MOD = 1e9 + 7;
      |           ^~~
a.cc:282:10: error: redefinition of 'const ll INF'
  282 | const ll INF = 1e18L + 5;
      |          ^~~
a.cc:124:10: note: 'const ll INF' previously defined here
  124 | const ll INF = 1e18L + 5;
      |          ^~~
a.cc:285:5: error: redefinition of 'int main()'
  285 | int main(){
      |     ^~~~
a.cc:127:5: note: 'int main()' previously defined here
  127 | int main(){
      |     ^~~~