Pentru această operație este nevoie să te autentifici.
Cod sursă (job #466024)
Utilizator |
|
IP | ascuns |
---|---|---|---|
Problemă | Lanterna | Compilator | cpp | 0,55 kb |
Rundă | Arhiva de probleme | Status | evaluat |
Dată | 4 apr. 2019 02:21:56 | Scor | 80 |
#include <bits/stdc++.h>
using namespace std;
int n, i;
unsigned long long int t[100010], s=0;
int main ()
{
ifstream cin ("lanterna.in");
ofstream cout ("lanterna.out");
cin>>n;
for(i=1; i<=n; i++)
cin>>t[i];
sort(t+1, t+n+1);
while (n-2>=2)
{
if (t[1]+2*t[2]+t[n]<=2*t[1]+t[n]+t[n-1])
s+=(t[1]+2*t[2]+t[n]);
else s+=2*t[1]+t[n]+t[n-1];
n-=2;
}
if (n==3) s+=t[1]+t[2]+t[3];
else if (n==2) s+=t[2];
cout<<s<<endl;
return 0;
}