Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cmath>
- #include<iomanip>
- #include<algorithm>
- #include<cstdlib>
- #include<cstring>
- #include<vector>
- #include<utility>
- #define ll long long
- #define sz(x) int(x.size())
- #define all(x) x.begin(),x.end()
- using namespace std;
- void Fast_IO(){
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- void solve(){
- ll n,a=-__LONG_LONG_MAX__,total=-__LONG_LONG_MAX__; cin>>n;
- ll arr[n];
- ll idx;
- for(ll i=0; i<n; i++){
- cin>>arr[i];
- if(arr[i]>a){
- a=arr[i];
- idx=i;
- }
- }
- for(ll i =0; i<n; i++){
- if(i==idx) continue;
- else{
- if(arr[idx]*arr[i]+arr[idx]-arr[i]> total) total = arr[idx]*arr[i]+arr[idx]-arr[i];
- }
- }
- cout<<total<<'\n';
- }
- int main(){
- Fast_IO();
- int t =1;
- cin>>t;
- while(t--){
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement