?
# | Author | Problem | Lang | Verdict | Time | Memory | Sent | Judged | |
---|---|---|---|---|---|---|---|---|---|
191085038 |
Practice: iamtanishq |
1406B - 26 | GNU C++20 (64) | Runtime error on test 2 | 62 ms | 812 KB | 2023-01-29 14:21:54 | 2023-01-29 14:21:54 |
// /* // You can have the world under your feet, // But all you do is cry, // I know you are scared of failing, // But Oh My Darlin, Give it a try. // IWRITESOMETIMES | Maansi :) // */ // #include <bits/stdc++.h> // using namespace std; // #define ll long long // #define ull unsigned long long // #define ld long double // #define pb push_back // #define mp make_pair // #define pii pair<int, int> // #define pll pair<ll, ll> // #define vi vector<int> // #define vll vector<ll> // #define vvi vector<vi> // #define F first // #define S second // #define all(v) v.begin(), v.end() // #define FOR(i, a, b) for (int i = a; i < b; i++) // #define RFOR(i, a, b) for (int i = a; i >= b; i--) // #define rep(i, n) FOR(i, 0, n) // #define RREP(i, n) RFOR(i, n, 0) // #define mod 1000000007 // #define inf 1000000000 // #define endl "\n" // #define srt(ar) sort(ar.begin(), ar.end()) // #define fastio \ // ios_base::sync_with_stdio(false); \ // cin.tie(NULL); \ // cout.tie(NULL); // #define pq priority_queue // #define rpq priority_queue<int, vi, greater<int>> // #define init std::fill(hash.begin(), hash.end(), -1) // #define FAST_IO(n) \ // cout.setf(ios::fixed); \ // cout.precision(n); // #define print(v) \ // rep(i, v.size()) \ // cout \ // << v[i] << " "; \ // cout << endl; // #define mii map<int, int> // ll power(ll x, ll y) { // ll res = 1; // while (y > 0) { // if (y & 1) // res = res * x; // y = y >> 1; // x = x * x; // } // return res; // } // void solve(){ // ll n; cin>>n; // vll ar(n); // rep(i, n)cin>>ar[i]; // ll case1 = INT64_MIN; // ll case2 = INT64_MIN; // ll case3 = INT64_MIN; // ll case4 = INT64_MIN; // // case 1 is when 2 negative and 3 positive // // case 2 is when 4 negative and 1 positive // vll neg; // vll pos; // for(int i = 0; i < n; i++){ // if(ar[i] < 0) neg.pb(ar[i]); // else break; // } // for(int i = n-1; i >= 0; i--){ // if(ar[i] >= 0) pos.pb(ar[i]); // else break; // } // // cout<<(pos.size()); // // cout<<(neg.size()); // if(neg.size() >= 2 && pos.size() >= 3){ // case1 = neg[0] * neg[1] * pos[0] * pos[1] * pos[2]; // } // if(pos.size() >= 1 && neg.size()>=4){ // case2 = pos[0] * neg[0] * neg[1] * neg[2] * neg[3]; // } // if(pos.size() == 0){ // case3 = 1; // for(int i = neg.size() - 1; i >= neg.size() - 5; i--){ // case3 *= neg[i]; // } // } // print(pos); // if(neg.size() == 0){ // case4 = 1; // for(int i = 0; i < 5; i++){ // case4 *= pos[i]; // } // } // cout<<case4<<endl; // // vll finalans; // // finalans.pb(case1); // // finalans.pb(case2); // // finalans.pb(case3); // // finalans.pb(case4); // // sort(all(finalans)); // // print(finalans); // // cout<<finalans[3]<<endl; // } // int main() // { // fastio; // int t = 1; // cin>>t; // while(t--){ // solve(); // } // return 0; // } /* You can have the world under your feet, But all you do is cry, I know you are scared of failing, But Oh My Darlin, Give it a try. IWRITESOMETIMES | Maansi :) */ #include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define ld long double #define pb push_back #define mp make_pair #define pii pair<int, int> #define pll pair<ll, ll> #define vi vector<int> #define vll vector<ll> #define vvi vector<vi> #define F first #define S second #define all(v) v.begin(), v.end() #define FOR(i, a, b) for (int i = a; i < b; i++) #define RFOR(i, a, b) for (int i = a; i >= b; i--) #define rep(i, n) FOR(i, 0, n) #define RREP(i, n) RFOR(i, n, 0) #define mod 1000000007 #define inf 1000000000 #define endl "\n" #define srt(ar) sort(ar.begin(), ar.end()) #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define pq priority_queue #define rpq priority_queue<int, vi, greater<int>> #define init std::fill(hash.begin(), hash.end(), -1) #define FAST_IO(n) \ cout.setf(ios::fixed); \ cout.precision(n); #define print(v) \ rep(i, v.size()) \ cout \ << v[i] << " "; \ cout << endl; #define mii map<int, int> ll power(ll x, ll y) { ll res = 1; while (y > 0) { if (y & 1) res = res * x; y = y >> 1; x = x * x; } return res; } bool comp(ll a, ll b){ return abs(a) <= abs(b); } void solve(){ int n; cin>>n; vll ar(n); rep(i,n) cin>>ar[i]; sort(all(ar), comp); // print(ar); long double prod = 1; int neg; int pos; for(int i = n-1; i >= n-5; i--){ prod *= ar[i]; if(ar[i] >= 0) pos = ar[i]; else neg = ar[i]; } long double ans1 = INT64_MIN; long double ans = INT64_MIN; // cout<<prod<<endl; // cout<<pos<<" "<<neg<<endl; if(prod < 0 && n - 6 >= 0){ for(int i = n - 6; i >= 0; i--){ if(pos==INT_MAX && neg == INT_MAX) break; if(ar[i] >= 0 && neg != INT_MAX){ ans = (prod/neg)*ar[i]; neg = INT_MAX; continue; } if(ar[i] < 0 && pos!=INT_MAX){ if(pos != 0) ans1 = (prod/pos) * ar[i]; else ans1 = 0; pos = INT_MAX; continue; } } if(ans1 == -0){ ans1 *= -1; } if(ans == -0) ans *= -1; cout<<max(max(prod,ans), ans1)<<endl; } else{ if(prod == -0) prod *= -1; cout<<prod<<endl; } } int main() { fastio; int t = 1; cin>>t; while(t--){ solve(); } return 0; }
?
?
?
?