Cod sursă (job #276494)

Utilizator avatar dianamaria Diana Cataros dianamaria IP ascuns
Problemă Lanterna Compilator cpp | 0,54 kb
Rundă Arhiva de probleme Status evaluat
Dată 6 feb. 2017 22:23:39 Scor 60
#include <fstream>
#include <algorithm>

using namespace std;
ifstream in ("lanterna.in");
ofstream out ("lanterna.out");

int v[100001];
int main()
{
    int n,i,timp=0;
    in>>n;
    for (i=1;i<=n;i++)
        in>>v[i];
    sort(v+1,v+n+1);
    while (n>3)
    {
        if (2*v[1]+v[n-1]+v[n]<v[1]+2*v[2]+v[n])
            timp+=2*v[1]+v[n-1]+v[n];
        else
            timp+=v[1]+2*v[2]+v[n];
        n-=2;
    }
    if (n==3)
        timp+=v[1]+v[2]+v[3];
    else
        timp+=v[2];
    out<<timp;
    return 0;
}