fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int n;
  7. cin>>n;
  8.  
  9. int b[n+1]; // 1 - based indexing
  10. for(int i=1; i<=n; i++)
  11. {
  12. cin>>b[i];
  13. }
  14.  
  15. int ans = -1;
  16.  
  17. for(int i=1; i<=n; i++)
  18. {
  19. int product = 1; // Initially the product will be 1
  20.  
  21. for(int j=i; j<=n; j++)
  22. {
  23. // product * current element
  24. product = product * b[j];
  25.  
  26. ans = max (ans , product); // take maximum of all of products
  27. }
  28. }
  29. cout<<ans;
  30.  
  31. return 0;
  32. }
Success #stdin #stdout 0s 5356KB
stdin
4
2 3 -2 4
stdout
6