Cod sursă (job #148870)

Utilizator avatar Radu_Galan Galan Radu Radu_Galan IP ascuns
Problemă Lanterna Compilator cpp | 0,47 kb
Rundă Arhiva de probleme Status evaluat
Dată 10 iun. 2015 14:08:38 Scor 20
#include <algorithm>
#include <fstream>
using namespace std;
ifstream in("lanterna.in");
ofstream out("lanterna.out");
int n,a,b,T[100009];
int main()
{in>> n;
for(int i=1; i<=n; i++) in >> T[i];sort(T+1, T+1+n);
double suma=0;
if(n == 3){suma += T[1] + T[2] + T[3];}
    else{suma += T[2];}
while(n > 3)
    {a = T[1] + T[2]*2 + T[n];
     b= T[1]*2 + T[n-1] + T[n];
    if(a>b)suma+=b; else suma+=a;
    n = n - 2;}
out << suma<< '\n';
out.close();
return 0;}