Cod sursă (job #374540)

Utilizator avatar lucametehau Metehau Luca Mihnea lucametehau IP ascuns
Problemă Lanterna Compilator cpp | 0.52 kb
Rundă Arhiva de probleme Status evaluat
Dată 1 apr. 2018 11:58:23 Scor 100
#include <fstream>
#include <algorithm>

using namespace std;

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

const int nmax = 100000;

int n;
long long sol;

int v[1 + nmax];

int main() {
  cin >> n;
  for(int i = 1; i <= n; i++)
    cin >> v[i];
  sort(v + 1, v + n + 1);
  int i = n;
  while(i > 3) {
    sol += min(v[1] * 2 + v[i - 1] + v[i], v[1] + 2 * v[2] + v[i]);
    i -= 2;
  }
  if(i == 3)
    sol += v[1] + v[2] + v[3];
  else
    sol += v[2];
  cout << sol;
  return 0;
}