Pentru această operație este nevoie să te autentifici.
Cod sursă (job #446621)
Utilizator |
|
IP | ascuns |
---|---|---|---|
Problemă | Lanterna | Compilator | cpp | 0,46 kb |
Rundă | Arhiva de probleme | Status | evaluat |
Dată | 14 mar. 2019 20:55:03 | Scor | 100 |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("lanterna.in");
ofstream fout("lanterna.out");
int a[100002], i;
long long aux1, aux2, s=0, n;
int main() {
fin >> n;
for (i=1; i<=n; i++)
fin >> a[i];
sort(a+1,a+n+1);
while (n>3) {
aux1=a[1]+2*a[2]+a[n];
aux2=a[n]+2*a[1]+a[n-1];
if (aux1 < aux2) s+=aux1; else s+=aux2;
n=n-2;
}
if (n==3) s+=a[1]+a[2]+a[3]; else
s+=a[2];
fout << s;
return 0;
}