Cod sursă (job #446032)

Utilizator avatar MaddoxX Mironica Vasile MaddoxX IP ascuns
Problemă Lanterna Compilator cpp | 0.44 kb
Rundă lasm_13_03_2019_10_12b Status evaluat
Dată 13 mar. 2019 22:44:18 Scor 0
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

ifstream cin("lanterna.in");
ofstream cout("lanterna.out");

int b, st, dr;
vector<int> a;
unsigned long long ans;

int main() {
	cin >> dr;
	for(int i=0; i<dr; i++)
		cin >> b,
		a.push_back(b);
	sort(a.begin(), a.end());
	
	while(st < dr) {
		ans += a[dr] + a[st];
		st++;
		dr--;
	}
	if(st == dr)
		ans += a[st];
	cout << ans;
	return 0;
}