Advertisement
Ahmed_Negm

Untitled

Apr 5th, 2022
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3. #include<iomanip>
  4. #include<algorithm>
  5. #include<cstdlib>
  6. #include<cstring>
  7. #include<vector>
  8. #include<utility>
  9.  
  10. #define ll long long
  11. #define sz(x) int(x.size())
  12. #define all(x) x.begin(),x.end()
  13. using namespace std;
  14.  
  15. void Fast_IO(){
  16.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  17.     #ifndef ONLINE_JUDGE
  18.         freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  19.     #endif
  20. }
  21.  
  22.  
  23.  
  24.  
  25.  
  26. void solve(){
  27.   ll n,a=-__LONG_LONG_MAX__,total=-__LONG_LONG_MAX__; cin>>n;
  28.   ll arr[n];
  29.   ll idx;
  30. for(ll i=0; i<n; i++){
  31.     cin>>arr[i];
  32.     if(arr[i]>a){
  33.         a=arr[i];
  34.         idx=i;
  35.     }
  36. }
  37. for(ll i =0; i<n; i++){
  38.     if(i==idx) continue;
  39.     else{
  40.         if(arr[idx]*arr[i]+arr[idx]-arr[i]> total) total = arr[idx]*arr[i]+arr[idx]-arr[i];
  41.     }
  42. }
  43.  
  44. cout<<total<<'\n';
  45.  
  46. }
  47.  
  48. int main(){
  49.     Fast_IO();
  50. int t =1;
  51. cin>>t;
  52. while(t--){
  53. solve();
  54. }
  55. return 0;
  56. }  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement