Cod sursă (job #447138)

Utilizator avatar mariabd Maria Burdila mariabd IP ascuns
Problemă Lanterna Compilator cpp | 0,43 kb
Rundă lasm_13_03_2019_10_12b Status evaluat
Dată 15 mar. 2019 14:59:36 Scor 100
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("lanterna.in");
ofstream fout("lanterna.out");
int n,x,y,a[100009];
long long s;
int main()
{
  fin>> n;
   for(int i=1; i<=n; i++) fin >> a[i];
sort(a+1, a+1+n);
while(n > 3){
x = a[1] + a[2]*2 + a[n];
y = a[1]*2 + a[n-1] + a[n];
s += min(x, y);
n = n - 2;}
if(n == 3){
      s += a[1] + a[2] + a[3];}
else{ s += a[2]; }
fout<< s;
return 0;
}