Untitled

mail@pastecode.io avatar
unknown
c_cpp
a month ago
366 B
1
Indexable
Never
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
  int n;
  cin >> n;

  long long niza[n], naj = 0, sum = 0;
  for(int i= 0; i < n; i++) {
    cin >> niza[i];
    sum += niza[i];
    naj = max(naj, niza[i]);
  }

  sum -= naj;
  if(naj > sum) {
    cout << naj * 2 << endl;
  }
  else {
    cout << sum + naj << endl;
  }

  return 0;
}
 
Leave a Comment