Advertisement
Josif_tepe

Untitled

Oct 3rd, 2021
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int maxn = 1e6 + 10;
  4. const int INF = 2e9 + 10;
  5. const int MOD = 1e9 + 7;
  6. typedef long long ll;
  7.  
  8. int main(){
  9.     ios_base::sync_with_stdio(false);
  10.     int n;
  11.     cin >> n;
  12.     vector<ll> v(n);
  13.     for(ll &x : v) {
  14.         cin >> x;
  15.     }
  16.     if(n == 1) {
  17.         cout << v[0] * 2 << endl;
  18.         return 0;
  19.     }
  20.     sort(v.begin(), v.end());
  21.     ll sum = 0;
  22.     for(int i = 0; i < n - 1; ++i) {
  23.         sum += v[i];
  24.     }
  25.     if(sum <= v[n - 1]){
  26.         cout << v[n - 1] * 2 << endl;
  27.     }
  28.     else {
  29.         cout << sum + v[n - 1] << endl;
  30.     }  
  31.     return 0;
  32. }
  33.                                                                                                            
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement