Cod sursă (job #545041)

Utilizator avatar o0o0o0o0o0o Dan Sclearov o0o0o0o0o0o IP ascuns
Problemă Lanterna Compilator cpp | 0,52 kb
Rundă lasm_19_03_2020_11 Status evaluat
Dată 19 mar. 2020 12:26:23 Scor 100
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

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

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

int main() {
	cin >> n;
	a.push_back(0);
	for(int i=1; i<=n; i++) {
		cin >> b;
		a.push_back(b);
	}
	sort(a.begin(), a.end());



	


  
	while(n > 3) {
		st = 2 * a[2] +   a[1]   + a[n];
		dr = 2 * a[1] + a[n - 1] + a[n];
		ans += min(st, dr);
		n -= 2;
	}



	ans += a[2];
	if(n & 1)
		ans += a[1] + a[3];
	cout << ans;
	return 0;
}