Cod sursă (job #803109)

Utilizator avatar deniscorman Corman Denis deniscorman IP ascuns
Problemă Lanterna Compilator cpp-32 | 0,59 kb
Rundă lasm_09_01_2025_clasa11 Status evaluat
Dată 9 ian. 2025 14:30:53 Scor 0
#include <bits/stdc++.h>

using namespace std;

int main() 
  {
    freopen("lanterna.in", "r", stdin);
    freopen("lanterna.out", "w", stdout);
    int n; cin >> n;
    vector<int> t(n);
    for (int i = 0; i < n; i++)
        cin >> t[i];
    sort(t.begin(), t.end());
    
    int k = 0 = 0;
    if (n == 3) 
      {
        k = t[2] + t[1]; 
        cout << t << endl;
        return 0;
      }
    while (n > 3) 
      {
        int a = t[1] + t[0] + t[n-1] + t[1];
        int b = t[1] + t[0] + t[n-1] + t[2];
        k += min(a, b);
        n--;
      }
    cout << k << endl;
    return 0;
  }