Advertisement
Josif_tepe

Untitled

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