fork download
  1. //Bai 20
  2.  
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5. #define el "\n"
  6. #define ll long long
  7. #define ull unsigned long long
  8. #define se second
  9. #define fi first
  10. #define be begin()
  11. #define en end()
  12. #define Faster cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
  13. int n;
  14. void Run()
  15. {
  16. cin >> n;
  17. vector<ll> vt1, vt2, vt3;
  18. ll ans = 1;
  19. while(n--)
  20. {
  21. ll x; cin >> x;
  22. if(x > 0) vt1.push_back(x);
  23. else if(x < 0) vt2.push_back(x);
  24. else vt3.push_back(x);
  25. }
  26. if(vt1.size() == 0 && vt2.size() == 0)
  27. {
  28. cout << 0;
  29. }
  30. else
  31. {
  32. if(vt1.size())
  33. {
  34. sort(vt1.begin(), vt1.end());
  35. for(auto x : vt1) ans *= x;
  36. }
  37. if(vt2.size())
  38. {
  39. sort(vt2.begin(), vt2.end(),greater<ll>());
  40. if(vt2.size() % 2)
  41. {
  42. for(int i = 1 ; i < vt2.size(); i++) ans*= vt2[i];
  43. }
  44. else
  45. {
  46. for(auto x : vt2) ans *= x;
  47. }
  48. }
  49. }
  50. if(vt1.size() == 0 && vt2.size() == 1) ans = vt2[0];
  51. if(ans < 0 && vt3.size()) ans = 0;
  52. cout << ans;
  53. }
  54. int main()
  55. {
  56. Faster;
  57. Run();
  58. return 0;
  59. }
  60.  
  61.  
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
01