Untitled

mail@pastecode.io avatar
unknown
c_cpp
3 years ago
491 B
1
Indexable
Never
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
const int maxn = 100005;
int main()
{
    int n;
    cin >> n;
    int niza[n];
    for(int i = 0; i < n; i++) {
        cin >> niza[i];
    }
    sort(niza, niza + n);
    long long sum = 0;
    for(int i = 0; i < n - 1; i++) {
        sum += niza[i];
    }
    if(sum >= niza[n - 1]) {
        cout << sum + niza[n - 1] << endl;
    }
    else {
        cout << niza[n - 1] * 2 << endl;
    }
    return 0;
}