j33vansh

Question 4 Eren Armin C++ Solution

Apr 22nd, 2022 (edited)
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4. int main(){
  5.     ios_base::sync_with_stdio(false);
  6.     cin.tie(NULL);
  7.     cout.tie(NULL);
  8.     int t,n;
  9.     cin>>t;
  10.     while(t--){
  11.     cin>>n;
  12.     vector<int> book(n);
  13.     ll sum=0;
  14.     for(int i=0;i<n;i++){
  15.         cin>>book[i];
  16.         sum+=book[i];
  17.     }
  18.     sort(book.begin(),book.end());
  19.     cout<<max(sum,(ll)book[n-1]*2)<<"\n";
  20.     }
  21.     return 0;
  22. }
Add Comment
Please, Sign In to add comment