Advertisement
Josif_tepe

Untitled

Mar 19th, 2024
619
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <queue>
  5. #include <cstring>
  6. using namespace std;
  7. typedef long long ll;
  8. const int maxn = 2e5 + 10;
  9. const ll MOD = 1e9 + 7;
  10.  
  11. int main() {
  12.     ios_base::sync_with_stdio(false);
  13.     int n;
  14.     cin >> n;
  15.    
  16.     vector<int> v(n);
  17.     for(int i = 0; i < n; i++) {
  18.         cin >> v[i];
  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(v[n - 1] > sum) {
  26.         cout << v[n - 1] * 2 << endl;
  27.     }
  28.     else {
  29.         cout << sum + v[n - 1] << endl;
  30.     }
  31.     return 0;
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement