Advertisement
Josif_tepe

Untitled

Jan 27th, 2023
933
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. int main() {
  5.     int n;
  6.     cin >> n;
  7.     long long niza[n];
  8.     for(int i = 0; i < n; i++)
  9.     {
  10.         cin >> niza[i];
  11.     }
  12.     sort(niza, niza + n);
  13.     long long zbir = 0;
  14.     for(int i = 0; i < n; i++)
  15.     {
  16.         zbir += niza[i];
  17.     }
  18.     zbir -= niza[n-1];
  19.     if(niza[n-1] > zbir)
  20.     {
  21.         cout << niza[n-1] * 2 << endl;
  22.     }
  23.     else{
  24.         cout << zbir + niza[n-1];
  25.     }
  26.     return 0;
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement