Pentru această operație este nevoie să te autentifici.

Cod sursă (job #654365)

Utilizator avatar TheAndrei Enache Andrei Alexandru TheAndrei IP ascuns
Problemă Lanterna Compilator cpp-32 | 0,77 kb
Rundă Arhiva de probleme Status evaluat
Dată 5 iul. 2022 17:42:29 Scor 10
#include <iostream>
#include <fstream>

using namespace std;

ifstream fin("lanterna.in");
ofstream fout("lanterna.out");

int main()
{
    int n, i, min1=1000001, min2=1000002, max1=0, max2=0, s=0, x=0;
    fin>>n;
    int t[n+1];
    for(i=1;i<=n;i++){
        fin>>t[i];
        if(t[i]<min1){
            min1=t[i];
        }
        if(t[i]<min2&&t[i]!=min1){
            min2=t[i];
        }
        if(t[i]>max1){
            max2=max1;
            max1=t[i];
        }
        else
            if(t[i]>max2)
                max2=t[i];


    }
    s=min2*3+max1+1;
    for(i=1;i<=n;i++){
        if(t[i]!=min1&&t[i]!=min2&&t[i]!=max1&&t[i]!=max2){
            s += t[i];
            s += min1;
        }
    }

    fout<<s;
    return 0;
}